Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Ding Xiang and committed by
Shuah Khan
3084a4ec 12a29115

+2
+2
tools/testing/selftests/vm/ksm_tests.c
··· 54 54 } 55 55 if (fprintf(f, "%lu", val) < 0) { 56 56 perror("fprintf"); 57 + fclose(f); 57 58 return 1; 58 59 } 59 60 fclose(f); ··· 73 72 } 74 73 if (fscanf(f, "%lu", val) != 1) { 75 74 perror("fscanf"); 75 + fclose(f); 76 76 return 1; 77 77 } 78 78 fclose(f);