mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-27 12:57:53 +00:00
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>
This commit is contained in:
parent
12a29115be
commit
3084a4ec7f
1 changed files with 2 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue