* [Patch] lib/mangle.c: fix a memory leak in the test case
@ 2012-06-20 8:42 Cong Wang
2012-06-21 8:44 ` Karel Zak
0 siblings, 1 reply; 2+ messages in thread
From: Cong Wang @ 2012-06-20 8:42 UTC (permalink / raw)
To: util-linux; +Cc: Cong Wang, Karel Zak
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);
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-06-21 8:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-20 8:42 [Patch] lib/mangle.c: fix a memory leak in the test case Cong Wang
2012-06-21 8:44 ` Karel Zak
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).