Skip to content

Commit

Permalink
[std] Prevent process stdin being closed twice
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 free_process, since that could cause us
to close a handle that no longer belongs to the process.
  • Loading branch information
tobil4sk committed Jan 16, 2025
1 parent de10ddd commit d4d3baa
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion libs/std/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ static void free_process( value vp ) {
# ifdef NEKO_WINDOWS
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 @@ -371,6 +373,7 @@ static value process_stdin_close( value vp ) {
# ifdef NEKO_WINDOWS
if( !CloseHandle(p->iwrite) )
neko_error();
p->iwrite = NULL;
# else
if( do_close(p->iwrite) )
neko_error();
Expand Down

0 comments on commit d4d3baa

Please sign in to comment.