Skip to content

Commit 23012db

Browse files
authored
[std] Prevent process stdin being closed twice (#300)
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.
1 parent de10ddd commit 23012db

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

libs/std/process.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ static void free_process( value vp ) {
8282
# ifdef NEKO_WINDOWS
8383
CloseHandle(p->eread);
8484
CloseHandle(p->oread);
85-
CloseHandle(p->iwrite);
85+
if (p->iwrite != NULL) {
86+
CloseHandle(p->iwrite);
87+
}
8688
CloseHandle(p->pinf.hProcess);
8789
CloseHandle(p->pinf.hThread);
8890
# else
@@ -371,6 +373,7 @@ static value process_stdin_close( value vp ) {
371373
# ifdef NEKO_WINDOWS
372374
if( !CloseHandle(p->iwrite) )
373375
neko_error();
376+
p->iwrite = NULL;
374377
# else
375378
if( do_close(p->iwrite) )
376379
neko_error();

0 commit comments

Comments
 (0)