* [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
* Re: [Patch] lib/mangle.c: fix a memory leak in the test case
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
0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2012-06-21 8:44 UTC (permalink / raw)
To: Cong Wang; +Cc: util-linux, Cong Wang
On Wed, Jun 20, 2012 at 04:42:05PM +0800, Cong Wang wrote:
> 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'
We usually ignore free-before-exit, but test programs are exception.
Applied, thanks.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.