mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 18:05:07 +00:00
Shell: Fix fd leak with pipes
Fixes the problem reported in #3073. While trying to write a test for this, I thought I'd use Shell -c 'for i in $(seq 100) { echo $i }' | head -n 1 but that makes the cpu spin at 100% and doesn't terminate even with this fix here. But at least piping disasm into head now works.
This commit is contained in:
parent
69fc91d974
commit
37d5e3e0df
1 changed files with 4 additions and 0 deletions
|
@ -535,6 +535,10 @@ RefPtr<Job> Shell::run_command(const AST::Command& command)
|
|||
perror("dup2(run)");
|
||||
return nullptr;
|
||||
}
|
||||
// dest_fd is closed via the `fds` collector, but rewiring.other_pipe_end->dest_fd
|
||||
// isn't yet in that collector when the first child spawns.
|
||||
if (rewiring.other_pipe_end && close(rewiring.other_pipe_end->dest_fd) < 0)
|
||||
perror("close other pipe end");
|
||||
}
|
||||
|
||||
fds.collect();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue