Skip to content

Commit 3084a4e

Browse files
Ding Xiangshuahkh
authored andcommitted
selftests: vm: Fix resource leak when return error
When return on an error path, file handle need to be closed to prevent resource leak Signed-off-by: Ding Xiang <[email protected]> Reviewed-by: Shuah Khan <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 12a2911 commit 3084a4e

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

tools/testing/selftests/vm/ksm_tests.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ static int ksm_write_sysfs(const char *file_path, unsigned long val)
5454
}
5555
if (fprintf(f, "%lu", val) < 0) {
5656
perror("fprintf");
57+
fclose(f);
5758
return 1;
5859
}
5960
fclose(f);
@@ -72,6 +73,7 @@ static int ksm_read_sysfs(const char *file_path, unsigned long *val)
7273
}
7374
if (fscanf(f, "%lu", val) != 1) {
7475
perror("fscanf");
76+
fclose(f);
7577
return 1;
7678
}
7779
fclose(f);

0 commit comments

Comments
 (0)