Skip to contentSkip to conversation

lib/mangle.c: fix a memory leak in the test case

PATCH In review Cong Wang 2 participants 2 messages Jun 20, 2012 – Jun 21, 2012

Subsystems (2)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

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.

---

lib/mangle.c +6 -2
index 656918c..faddeb8 100644
@@ -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);
maintainer
#1 lore raw
Quoted 6 lines · Cong Wang

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'

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