diff options
author | Ding Xiang <dingxiang@cmss.chinamobile.com> | 2022-06-15 12:36:29 +0300 |
---|---|---|
committer | Shuah Khan <skhan@linuxfoundation.org> | 2022-06-16 23:14:08 +0300 |
commit | 3084a4ec7f9bb1ec90036cfd01b1abadc5dd4fb2 (patch) | |
tree | 07998824250d408bdefed267920bbad0e9e84732 /tools/testing/selftests/vm | |
parent | 12a29115be72dfc72372af9ded4bc4ae7113a729 (diff) | |
download | linux-3084a4ec7f9bb1ec90036cfd01b1abadc5dd4fb2.tar.xz |
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 <dingxiang@cmss.chinamobile.com>
Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'tools/testing/selftests/vm')
-rw-r--r-- | tools/testing/selftests/vm/ksm_tests.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/tools/testing/selftests/vm/ksm_tests.c b/tools/testing/selftests/vm/ksm_tests.c index 2fcf24312da8..f5e4e0bbd081 100644 --- a/tools/testing/selftests/vm/ksm_tests.c +++ b/tools/testing/selftests/vm/ksm_tests.c @@ -54,6 +54,7 @@ static int ksm_write_sysfs(const char *file_path, unsigned long val) } if (fprintf(f, "%lu", val) < 0) { perror("fprintf"); + fclose(f); return 1; } fclose(f); @@ -72,6 +73,7 @@ static int ksm_read_sysfs(const char *file_path, unsigned long *val) } if (fscanf(f, "%lu", val) != 1) { perror("fscanf"); + fclose(f); return 1; } fclose(f); |