summaryrefslogtreecommitdiff
path: root/src/w32proc.c
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2022-07-17 15:44:50 +0300
committerEli Zaretskii <eliz@gnu.org>2022-07-17 15:44:50 +0300
commit637436970f34f860d50f73a514b3bafd0c5cace7 (patch)
treef9f1fba2434ad07a84eecade8f0306d2be4111e2 /src/w32proc.c
parent202c12a24b89a3b8a923adba4d6bab0894b1a16e (diff)
downloademacs-637436970f34f860d50f73a514b3bafd0c5cace7.tar.gz
Fix leaking of file descriptors due to pipe processes on MS-Windows
* src/w32proc.c (reader_thread): Wait for 'sys_close' to finish processing the pipe read descriptor, before trying to close it. * src/w32.c (sys_close): Attempt to detect when the reader thread already exited, so that it would be possible to close descriptors open by pipe processes for reading from the pipe. (Bug#56606)
Diffstat (limited to 'src/w32proc.c')
-rw-r--r--src/w32proc.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/w32proc.c b/src/w32proc.c
index 7acfba64d70..f771ebc8511 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -1287,10 +1287,21 @@ reader_thread (void *arg)
}
/* If this thread was reading from a pipe process, close the
descriptor used for reading, as sys_close doesn't in that case. */
- if (fd_info[fd].flags == FILE_DONT_CLOSE)
+ if ((fd_info[fd].flags & FILE_DONT_CLOSE) == FILE_DONT_CLOSE)
{
- fd_info[fd].flags = 0;
- _close (fd);
+ int i;
+ /* If w32.c:sys_close is still processing this descriptor, wait
+ for a while for it to finish. */
+ for (i = 0; i < 5; i++)
+ {
+ if (fd_info[fd].flags == FILE_DONT_CLOSE)
+ {
+ fd_info[fd].flags = 0;
+ _close (fd);
+ break;
+ }
+ Sleep (5);
+ }
}
return 0;
}