[LTP] [PATCH] syscalls/pipe06: Rewrite the test using new LTP API
Petr Vorel
pvorel@suse.cz
Tue Jul 18 10:23:13 CEST 2023
Hi Avinesh,
> testcases/kernel/syscalls/pipe/pipe06.c | 133 ++++++------------------
...
> +static void setup(void)
> {
> + int max_fds;
> - /* reset tst_count in case we are looping */
> - tst_count = 0;
> + max_fds = getdtablesize();
> + tst_res(TINFO, "getdtablesize() = %d", max_fds);
> + opened_fds = SAFE_MALLOC(max_fds * sizeof(int));
You don't free opened_fds in cleanup, that would be a memory leak.
...
> +static void cleanup(void)
> {
> + for (int i = 0; i < num_opened_fds; i++)
> + SAFE_CLOSE(opened_fds[i]);
> }
> +
> +static struct tst_test test = {
> + .setup = setup,
> + .cleanup = cleanup,
> + .test_all = run
> +};
I suggest to fix it with patch below.
With that:
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
+++ testcases/kernel/syscalls/pipe/pipe06.c
@@ -12,6 +12,7 @@
* limit on the number of open file descriptors has been reached.
*/
+#include <stdlib.h>
#include "tst_test.h"
static int fds[2];
@@ -43,6 +44,9 @@ static void cleanup(void)
{
for (int i = 0; i < num_opened_fds; i++)
SAFE_CLOSE(opened_fds[i]);
+
+ if (opened_fds)
+ free(opened_fds);
}
static struct tst_test test = {
More information about the ltp
mailing list