[PATCH] selftests/timens/procfs: Fix Resource leak proc in read_proc_uptime

liuye posted 1 patch 11 months ago
tools/testing/selftests/timens/procfs.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] selftests/timens/procfs: Fix Resource leak proc in read_proc_uptime
Posted by liuye 11 months ago
    Exception branch returns without closing proc.
Signed-off-by: liuye <liuye@kylinos.cn>
---
 tools/testing/selftests/timens/procfs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/testing/selftests/timens/procfs.c b/tools/testing/selftests/timens/procfs.c
index 1833ca97eb24..e47844a73c31 100644
--- a/tools/testing/selftests/timens/procfs.c
+++ b/tools/testing/selftests/timens/procfs.c
@@ -79,9 +79,11 @@ static int read_proc_uptime(struct timespec *uptime)
 	if (fscanf(proc, "%lu.%02lu", &up_sec, &up_nsec) != 2) {
 		if (errno) {
 			pr_perror("fscanf");
+			fclose(proc);
 			return -errno;
 		}
 		pr_err("failed to parse /proc/uptime");
+		fclose(proc);
 		return -1;
 	}
 	fclose(proc);
-- 
2.25.1