fix(PIProcess): handle fork() failure (return value -1)
fork() can return -1 on error (too many processes, out of memory). The old code treated pid_ == -1 as a successful fork, entering the parent branch and calling waitpid(-1, ...) which waits for ANY child process. Added explicit check: close pipes, free memory, and return on fork failure.
This commit is contained in:
@@ -319,6 +319,13 @@ void PIProcess::startProc(bool detached) {
|
|||||||
auto largs = convertToCharArrays(args);
|
auto largs = convertToCharArrays(args);
|
||||||
auto lenv = convertToCharArrays(env);
|
auto lenv = convertToCharArrays(env);
|
||||||
int pid_ = fork();
|
int pid_ = fork();
|
||||||
|
if (pid_ < 0) {
|
||||||
|
piCoutObj << "\"fork\" error: " << errorString();
|
||||||
|
PRIVATE->closeAllPipes();
|
||||||
|
delete[] largs;
|
||||||
|
delete[] lenv;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!detached) PRIVATE->pid = pid_;
|
if (!detached) PRIVATE->pid = pid_;
|
||||||
if (pid_ == 0) {
|
if (pid_ == 0) {
|
||||||
if (!wd.isEmpty()) {
|
if (!wd.isEmpty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user