Skip to contentSkip to conversation

: Fix memory leaks and remove redundant code

PATCH In review Manjeet Pawar 2 participants 2 messages May 28, 2015 – Jun 1, 2015 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 : Fix memory leaks and remove redundant code

From: Manjeet Pawar <[email protected]>
Subject: [PATCH] lib/self_exec.c: free args before returning from function to avoid memory leaks and remove redundant code in self_exec()

This patch free args before returning from function to avoid memory leaks and remove redundant code in self_exec()

---
 lib/self_exec.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/self_exec.c +3 -3
index 06af313..e8f1ee6 100644
@@ -117,6 +117,7 @@ void maybe_run_child(void (*child) (), char *fmt, ...)
 				}
 				if (j != i) {
 					va_end(ap);
+					free(args);
 					return;
 				}
 				break;
@@ -144,7 +145,7 @@ void maybe_run_child(void (*child) (), char *fmt, ...)
 		}
 
 		va_end(ap);
-
+		free(args);
 		if (chdir(child_dir) < 0)
 			tst_brkm(TBROK, NULL,
 				 "Could not change to %s for child", child_dir);
@@ -170,8 +171,7 @@ int self_exec(char *argv0, char *fmt, ...)
 	}
 
 	arg = strdup(tmp_cwd);
-
-	if ((arg = strdup(tmp_cwd)) == NULL) {
+	if (arg == NULL) {
 		tst_resm(TBROK, "Could not produce self_exec string");
 		return -1;
 	}
Signature · 7 lines
1.7.9.5

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw

Hi!
Pushed, thanks.

Signature · 8 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list