[svn:parrot] r40319 - trunk/config/gen/platform/generic

chromatic at svn.parrot.org chromatic at svn.parrot.org
Tue Jul 28 23:56:44 UTC 2009


Author: chromatic
Date: Tue Jul 28 23:56:43 2009
New Revision: 40319
URL: https://trac.parrot.org/parrot/changeset/40319

Log:
[config] Plugged a short-lived, very theoretical memory leak when exec()ing a
child process fails.  It's unlikely, but it's a good practice to pair up
allocating functions and their corresponding frees anyway.  (Coverity CID #358)

Modified:
   trunk/config/gen/platform/generic/exec.c

Modified: trunk/config/gen/platform/generic/exec.c
==============================================================================
--- trunk/config/gen/platform/generic/exec.c	Tue Jul 28 23:44:46 2009	(r40318)
+++ trunk/config/gen/platform/generic/exec.c	Tue Jul 28 23:56:43 2009	(r40319)
@@ -1,6 +1,6 @@
 /*
  * $Id$
- * Copyright (C) 2004-2008, Parrot Foundation.
+ * Copyright (C) 2004-2009, Parrot Foundation.
  */
 
 /*
@@ -48,24 +48,25 @@
     /* Are we the parent or child? */
     if (child) {
         /* parent */
-        int status;
-        pid_t returnstat;
-        returnstat = waitpid(child, &status, 0);
+        int   status;
+        pid_t returnstat = waitpid(child, &status, 0);
         UNUSED(returnstat);
         return status;
     }
     else {
-        /* child. Be horribly profligate with memory, since we're
-           about to be something else */
-        int status;
-        status = execlp("sh", "sh", "-c",
-            Parrot_str_to_cstring(interp, command), (void *)NULL);
-        /* if we get here, something's horribly wrong... */
-        if (status) {
+        /* child */
+        char *cmd    = Parrot_str_to_cstring(interp, command);
+        int   status = execlp("sh", "sh", "-c", cmd, (void *)NULL);
+
+        /* if we get here, something's horribly wrong, but free anyway... */
+        mem_sys_free(cmd);
+
+        if (status)
             exit(status);
-        }
     }
-    return 1;    /* make gcc happy */
+
+    /* make gcc happy */
+    return 1;
 }
 
 /*


More information about the parrot-commits mailing list