Util-Linux package development
 help / color / mirror / Atom feed
From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: Sami Kerola <kerolasa@iki.fi>
Subject: [PATCH 3/4] logger: fix memory leaks [asan]
Date: Mon, 11 Sep 2017 20:57:16 +0100	[thread overview]
Message-ID: <20170911195717.817-3-kerolasa@iki.fi> (raw)
In-Reply-To: <20170911195717.817-1-kerolasa@iki.fi>

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 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


  parent reply	other threads:[~2017-09-11 19:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-11 19:57 [PATCH 1/4] uuidparse: fix stack-buffer-overflow [asan] Sami Kerola
2017-09-11 19:57 ` [PATCH 2/4] libsmartcols: fix heap-buffer-overflow [asan] Sami Kerola
2017-09-15 11:47   ` Karel Zak
2017-09-11 19:57 ` Sami Kerola [this message]
2017-09-15 11:05   ` [PATCH 3/4] logger: fix memory leaks [asan] Karel Zak
2017-09-16  0:54     ` J William Piggott
2017-09-16  7:31       ` Sami Kerola
2017-09-18  8:55         ` Karel Zak
2017-09-18  9:40         ` Karel Zak
2017-09-11 19:57 ` [PATCH 4/4] partx: fix memory leak [asan] Sami Kerola
2017-09-15 11:33 ` [PATCH 1/4] uuidparse: fix stack-buffer-overflow [asan] Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170911195717.817-3-kerolasa@iki.fi \
    --to=kerolasa@iki.fi \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox