From 8b4cf5c15b9401b066dafc46ceb9559f2712c666 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Fri, 22 Jan 2010 00:09:56 +0100 Subject: [PATCH] Fix memory leak and bad error reporting with posix_spawn(): * 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libratbox/src/unix.c b/libratbox/src/unix.c index 1472253..5b990c5 100644 --- a/libratbox/src/unix.c +++ b/libratbox/src/unix.c @@ -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; }