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:
parent
d06f3da955
commit
dcb22e07b9
1 changed files with 6 additions and 2 deletions
|
@ -48,6 +48,7 @@ rb_spawn_process(const char *path, const char **argv)
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
const void *arghack = argv;
|
const void *arghack = argv;
|
||||||
char **myenviron;
|
char **myenviron;
|
||||||
|
int error;
|
||||||
posix_spawnattr_t spattr;
|
posix_spawnattr_t spattr;
|
||||||
posix_spawnattr_init(&spattr);
|
posix_spawnattr_init(&spattr);
|
||||||
#ifdef POSIX_SPAWN_USEVFORK
|
#ifdef POSIX_SPAWN_USEVFORK
|
||||||
|
@ -58,9 +59,12 @@ rb_spawn_process(const char *path, const char **argv)
|
||||||
#else
|
#else
|
||||||
myenviron = environ;
|
myenviron = environ;
|
||||||
#endif
|
#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;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue