Skip to content

Commit 87fe26c

Browse files
authored
[std] Prevent process stdin being closed twice (#743)
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.
1 parent 587ef0e commit 87fe26c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/std/process.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ static void process_finalize( vprocess *p ) {
6161
# ifdef HL_WIN
6262
CloseHandle(p->eread);
6363
CloseHandle(p->oread);
64-
CloseHandle(p->iwrite);
64+
if (p->iwrite != NULL) {
65+
CloseHandle(p->iwrite);
66+
}
6567
CloseHandle(p->pinf.hProcess);
6668
CloseHandle(p->pinf.hThread);
6769
# else
@@ -235,6 +237,7 @@ HL_PRIM bool hl_process_stdin_close( vprocess *p ) {
235237
# ifdef HL_WIN
236238
if( !CloseHandle(p->iwrite) )
237239
return false;
240+
p->iwrite = NULL;
238241
# else
239242
if( close(p->iwrite) )
240243
return false;

0 commit comments

Comments
 (0)