Skip to content

Commit

Permalink
fix resource leak of self-pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
sekiguchi-nagisa committed Apr 17, 2024
1 parent 4a34368 commit 044d3c6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

- bugfix code generation of catch block with nested blocks (fix potential resource leak)
- correctly set ``PIPESTATUS`` when throw error from last-pipe
- fix resource leak of file descriptor (self-pipe) when fork failed

## [0.33.2] - 2024-04-11

Expand Down
3 changes: 2 additions & 1 deletion src/vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ static Value toCmdDesc(const ArrayObject &argvObj) {
bool VM::forkAndExec(ARState &state, const char *filePath, const ArrayObject &argvObj,
Value &&redirConfig) {
// setup self pipe
int selfPipe[2];
pipe_t selfPipe;
if (pipe(selfPipe) < 0) {
fatal_perror("pipe creation error");
}
Expand All @@ -786,6 +786,7 @@ bool VM::forkAndExec(ARState &state, const char *filePath, const ArrayObject &ar
const auto procOp = resolveProcOp(state, ForkKind::NONE);
auto proc = Proc::fork(state, pgid, procOp);
if (proc.pid() == -1) {
closeAllPipe(selfPipe);
raiseCmdError(state, argvObj.getValues()[0].asCStr(), EAGAIN);
return false;
} else if (proc.pid() == 0) { // child
Expand Down

0 comments on commit 044d3c6

Please sign in to comment.