lib/mangle.c: fix a memory leak in the test case
Subsystems (2)
PATCH 1/1 lib/mangle.c: fix a memory leak in the test case
From: Cong Wang <[email protected]>
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 <[email protected]>
Cc Karel Zak <[email protected]>
Signed-off-by Cong Wang <[email protected]>
---
lib/mangle.c +6 -2
@@ -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 );
Karel Zak
maintainerQuoted 6 lines · Cong Wang
From: Cong Wang <[email protected]>
Marek reported there is a memory leak in
lib/mangle.cCC 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
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com