Blame SOURCES/0005-sysfs.c-prevent-mem-leak-in-sysfs_node_read.patch

8f4a09
From cc1d7d17c6d2df0f603932becf238fdf264a9e30 Mon Sep 17 00:00:00 2001
8f4a09
From: Pingfan Liu <piliu@redhat.com>
8f4a09
Date: Thu, 10 Jun 2021 11:17:40 +0800
8f4a09
Subject: [PATCH 5/6] sysfs.c: prevent mem leak in sysfs_node_read()
8f4a09
8f4a09
Signed-off-by: Pingfan Liu <piliu@redhat.com>
8f4a09
---
8f4a09
 sysfs.c | 23 +++++++++++++++--------
8f4a09
 1 file changed, 15 insertions(+), 8 deletions(-)
8f4a09
8f4a09
diff --git a/sysfs.c b/sysfs.c
8f4a09
index 9ddf50d..a35c4b5 100644
8f4a09
--- a/sysfs.c
8f4a09
+++ b/sysfs.c
8f4a09
@@ -33,7 +33,7 @@ hidden char *sysfs_read(char *name)
8f4a09
 
8f4a09
 hidden int sysfs_node_read(struct bitmask *mask, char *fmt, ...)
8f4a09
 {
8f4a09
-	int n;
8f4a09
+	int n, ret = 0;
8f4a09
 	va_list ap;
8f4a09
 	char *p, *fn, *m, *end;
8f4a09
 	int num;
8f4a09
@@ -51,12 +51,18 @@ hidden int sysfs_node_read(struct bitmask *mask, char *fmt, ...)
8f4a09
 	m = p;
8f4a09
 	do {
8f4a09
 		num = strtol(m, &end, 0);
8f4a09
-		if (m == end)
8f4a09
-			return -1;
8f4a09
-		if (num < 0)
8f4a09
-			return -2;
8f4a09
-		if (num >= numa_num_task_nodes())
8f4a09
-			return -1;
8f4a09
+		if (m == end) {
8f4a09
+			ret = -1;
8f4a09
+			goto out;
8f4a09
+		}
8f4a09
+		if (num < 0) {
8f4a09
+			ret = -2;
8f4a09
+			goto out;
8f4a09
+		}
8f4a09
+		if (num >= numa_num_task_nodes()) {
8f4a09
+			ret = -1;
8f4a09
+			goto out;
8f4a09
+		}
8f4a09
 		numa_bitmask_setbit(mask, num);
8f4a09
 
8f4a09
 		/* Continuation not supported by kernel yet. */
8f4a09
@@ -64,6 +70,7 @@ hidden int sysfs_node_read(struct bitmask *mask, char *fmt, ...)
8f4a09
 		while (isspace(*m) || *m == ',')
8f4a09
 			m++;
8f4a09
 	} while (isdigit(*m));
8f4a09
+out:
8f4a09
 	free(p);
8f4a09
-	return 0;
8f4a09
+	return ret;
8f4a09
 }
8f4a09
-- 
8f4a09
2.29.2
8f4a09