]> jfr.im git - solanum.git/commitdiff
Fix memory leak and bad error reporting with posix_spawn():
authorJilles Tjoelker <redacted>
Thu, 21 Jan 2010 23:09:56 +0000 (00:09 +0100)
committerJilles Tjoelker <redacted>
Thu, 21 Jan 2010 23:09:56 +0000 (00:09 +0100)
* an initialized posix_spawnattr_t must be destroyed
* posix_spawn() returns an error number instead of setting errno

libratbox trunk r26730

libratbox/src/unix.c

index 14722538ac1724ab83609fc2ec991287117c45f5..5b990c525e66a801111b52c01b23d6b8274dd0fb 100644 (file)
@@ -48,6 +48,7 @@ rb_spawn_process(const char *path, const char **argv)
        pid_t pid;
        const void *arghack = argv;
        char **myenviron;
+       int error;
        posix_spawnattr_t spattr;
        posix_spawnattr_init(&spattr);
 #ifdef POSIX_SPAWN_USEVFORK
@@ -58,9 +59,12 @@ rb_spawn_process(const char *path, const char **argv)
 #else
        myenviron = environ;
 #endif
-       if(posix_spawn(&pid, path, NULL, &spattr, arghack, myenviron))
+       error = posix_spawn(&pid, path, NULL, &spattr, arghack, myenviron);
+       posix_spawnattr_destroy(&spattr);
+       if (error != 0)
        {
-               return -1;
+               errno = error;
+               pid = -1;
        }
        return pid;
 }