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:
2026-08-05 17:39:38 +03:00
parent 13a9a75f79
commit 27a9f05d65
+7
View File
@@ -319,6 +319,13 @@ void PIProcess::startProc(bool detached) {
auto largs = convertToCharArrays(args);
auto lenv = convertToCharArrays(env);
int pid_ = fork();
if (pid_ < 0) {
piCoutObj << "\"fork\" error: " << errorString();
PRIVATE->closeAllPipes();
delete[] largs;
delete[] lenv;
return;
}
if (!detached) PRIVATE->pid = pid_;
if (pid_ == 0) {
if (!wd.isEmpty()) {