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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



    Exception branch returns without closing fptr.
Signed-off-by: liuye <liuye@xxxxxxxxxx>
---
 tools/testing/selftests/prctl/set-process-name.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

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);
 }
 
-- 
2.25.1





[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux