Commit 3084a4ec authored by Ding Xiang's avatar Ding Xiang Committed by Shuah Khan

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: default avatarDing Xiang <dingxiang@cmss.chinamobile.com>
Reviewed-by: default avatarShuah Khan <skhan@linuxfoundation.org>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent 12a29115
...@@ -54,6 +54,7 @@ static int ksm_write_sysfs(const char *file_path, unsigned long val) ...@@ -54,6 +54,7 @@ static int ksm_write_sysfs(const char *file_path, unsigned long val)
} }
if (fprintf(f, "%lu", val) < 0) { if (fprintf(f, "%lu", val) < 0) {
perror("fprintf"); perror("fprintf");
fclose(f);
return 1; return 1;
} }
fclose(f); fclose(f);
...@@ -72,6 +73,7 @@ static int ksm_read_sysfs(const char *file_path, unsigned long *val) ...@@ -72,6 +73,7 @@ static int ksm_read_sysfs(const char *file_path, unsigned long *val)
} }
if (fscanf(f, "%lu", val) != 1) { if (fscanf(f, "%lu", val) != 1) {
perror("fscanf"); perror("fscanf");
fclose(f);
return 1; return 1;
} }
fclose(f); fclose(f);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment