[PATCH 3/4] logger: fix memory leaks [asan]

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

 



Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 misc-utils/logger.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index f6fb350cc..4eba778b9 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -606,25 +606,30 @@ static char *strdup_structured_data(struct structured_data *sd)
 
 	xasprintf(&res, "[%s %s]", sd->id,
 			(tmp = strv_join(sd->params, " ")));
+	free(sd->id);
+	strv_free(sd->params);
 	free(tmp);
 	return res;
 }
 
 static char *strdup_structured_data_list(struct list_head *ls)
 {
-	struct list_head *p;
+	struct list_head *p, *pnext;
 	char *res = NULL;
 
-	list_for_each(p, ls) {
+	list_for_each_safe(p, pnext, ls) {
 		struct structured_data *sd = list_entry(p, struct structured_data, sds);
 		char *one = strdup_structured_data(sd);
 		char *tmp = res;
 
-		if (!one)
+		if (!one) {
+			free(tmp);
 			continue;
+		}
 		res = strappend(tmp, one);
 		free(tmp);
 		free(one);
+		free(sd);
 	}
 
 	return res;
@@ -979,6 +984,7 @@ static void logger_stdin(struct logger_ctl *ctl)
 		if (c == '\n')	/* discard line terminator */
 			c = getchar();
 	}
+	free(buf);
 }
 
 static void logger_close(const struct logger_ctl *ctl)
-- 
2.14.1

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux