diff mbox series

selftests/prctl/set-process-name: Fix Resource leak fptr in check_name

Message ID 20250114080410.108067-1-liuye@kylinos.cn (mailing list archive)
State New
Headers show
Series selftests/prctl/set-process-name: Fix Resource leak fptr in check_name | expand

Commit Message

liuye Jan. 14, 2025, 8:04 a.m. UTC
Exception branch returns without closing fptr.
Signed-off-by: liuye <liuye@kylinos.cn>
---
 tools/testing/selftests/prctl/set-process-name.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
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..625218fa0379 100644
--- a/tools/testing/selftests/prctl/set-process-name.c
+++ b/tools/testing/selftests/prctl/set-process-name.c
@@ -66,14 +66,18 @@  int check_name(void)
 		return -EIO;
 
 	fscanf(fptr, "%s", output);
-	if (ferror(fptr))
+	if (ferror(fptr)) {
+		fclose(fptr);
 		return -EIO;
+	}
 
 	int res = prctl(PR_GET_NAME, name, NULL, NULL, NULL);
 
-	if (res < 0)
+	if (res < 0) {
+		fclose(fptr);
 		return -errno;
-
+	}
+	fclose(fptr);
 	return !strcmp(output, name);
 }