Skip to content

Commit 8f4ab7d

Browse files
Yuuoniympe
authored andcommitted
selftests/powerpc: Fix resource leaks
In check_all_cpu_dscr_defaults, opendir() opens the directory stream. Add missing closedir() in the error path to release it. In check_cpu_dscr_default, open() creates an open file descriptor. Add missing close() in the error path to release it. Fixes: ebd5858 ("selftests/powerpc: Add test for all DSCR sysfs interfaces") Signed-off-by: Miaoqian Lin <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 6f3a81b commit 8f4ab7d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ static int check_cpu_dscr_default(char *file, unsigned long val)
2424
rc = read(fd, buf, sizeof(buf));
2525
if (rc == -1) {
2626
perror("read() failed");
27+
close(fd);
2728
return 1;
2829
}
2930
close(fd);
@@ -65,8 +66,10 @@ static int check_all_cpu_dscr_defaults(unsigned long val)
6566
if (access(file, F_OK))
6667
continue;
6768

68-
if (check_cpu_dscr_default(file, val))
69+
if (check_cpu_dscr_default(file, val)) {
70+
closedir(sysfs);
6971
return 1;
72+
}
7073
}
7174
closedir(sysfs);
7275
return 0;

0 commit comments

Comments
 (0)