util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cong Wang <amwang@redhat.com>
To: util-linux@vger.kernel.org
Cc: Cong Wang <xiyou.wangcong@gmail.com>, Karel Zak <kzak@redhat.com>
Subject: [Patch] lib/mangle.c: fix a memory leak in the test case
Date: Wed, 20 Jun 2012 16:42:05 +0800	[thread overview]
Message-ID: <1340181725-5382-1-git-send-email-amwang@redhat.com> (raw)

From: Cong Wang <xiyou.wangcong@gmail.com>

Marek reported there is a memory leak in lib/mangle.c

  CC       mangle.o
mangle.c:160:9: warning: Memory is never released; potential leak of memory pointed to by 'ss'

This patch fixes it.

Reported-by: Marek Otahal <markotahal@gmail.com>
Cc: Karel Zak <kzak@redhat.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>

---
diff --git a/lib/mangle.c b/lib/mangle.c
index 656918c..faddeb8 100644
--- a/lib/mangle.c
+++ b/lib/mangle.c
@@ -131,14 +131,18 @@ char *unmangle(const char *s, char **end)
 #include <errno.h>
 int main(int argc, char *argv[])
 {
+	char *p = NULL;
 	if (argc < 3) {
 		fprintf(stderr, "usage: %s --mangle|unmangle <string>\n",
 						program_invocation_short_name);
 		return EXIT_FAILURE;
 	}
 
-	if (!strcmp(argv[1], "--mangle"))
-		printf("mangled: '%s'\n", mangle(argv[2]));
+	if (!strcmp(argv[1], "--mangle")) {
+		p = mangle(argv[2]);
+		printf("mangled: '%s'\n", p);
+		free(p);
+	}
 
 	else if (!strcmp(argv[1], "--unmangle")) {
 		char *x = unmangle(argv[2], NULL);

             reply	other threads:[~2012-06-20  8:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-20  8:42 Cong Wang [this message]
2012-06-21  8:44 ` [Patch] lib/mangle.c: fix a memory leak in the test case 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=1340181725-5382-1-git-send-email-amwang@redhat.com \
    --to=amwang@redhat.com \
    --cc=kzak@redhat.com \
    --cc=util-linux@vger.kernel.org \
    --cc=xiyou.wangcong@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).