diff mbox series

selftests: prctl: Fix resource leaks

Message ID 20241128061827.4165-1-liujing@cmss.chinamobile.com (mailing list archive)
State New
Headers show
Series selftests: prctl: Fix resource leaks | expand

Commit Message

liujing Nov. 28, 2024, 6:18 a.m. UTC
After using the fopen function successfully, you need to call
fclose to close the file before finally returning.

Signed-off-by: liujing <liujing@cmss.chinamobile.com>
diff mbox series

Patch

diff --git a/tools/testing/selftests/prctl/set-process-name.c b/tools/testing/selftests/prctl/set-process-name.c
index 562f707ba771..7be7afff0cd2 100644
--- a/tools/testing/selftests/prctl/set-process-name.c
+++ b/tools/testing/selftests/prctl/set-process-name.c
@@ -66,9 +66,12 @@  int check_name(void)
 		return -EIO;
 
 	fscanf(fptr, "%s", output);
-	if (ferror(fptr))
+	if (ferror(fptr)) {
+		fclose(fptr);
 		return -EIO;
+	}
 
+	fclose(fptr);
 	int res = prctl(PR_GET_NAME, name, NULL, NULL, NULL);
 
 	if (res < 0)