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
This commit is contained in:
Jilles Tjoelker 2010-01-22 00:09:56 +01:00
parent d06f3da955
commit dcb22e07b9

View 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;
}