Skip to content

Commit

Permalink
[std] Prevent process stdin being closed twice (#743)
Browse files Browse the repository at this point in the history
When running `process_stdin_close`, the handle is made available again
and may be reused in another part of the program. This means that it is
not safe to rerun `CloseHandle` in `process_finalize`, since that could
cause us to close a handle that no longer belongs to the process.
  • Loading branch information
tobil4sk authored Jan 16, 2025
1 parent 587ef0e commit 87fe26c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/std/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ static void process_finalize( vprocess *p ) {
# ifdef HL_WIN
CloseHandle(p->eread);
CloseHandle(p->oread);
CloseHandle(p->iwrite);
if (p->iwrite != NULL) {
CloseHandle(p->iwrite);
}
CloseHandle(p->pinf.hProcess);
CloseHandle(p->pinf.hThread);
# else
Expand Down Expand Up @@ -235,6 +237,7 @@ HL_PRIM bool hl_process_stdin_close( vprocess *p ) {
# ifdef HL_WIN
if( !CloseHandle(p->iwrite) )
return false;
p->iwrite = NULL;
# else
if( close(p->iwrite) )
return false;
Expand Down

0 comments on commit 87fe26c

Please sign in to comment.