wrowe 2002/12/28 12:29:13
Modified: file_io/win32 open.c
Log:
Remove the segfault from testfile.c and introduce new breakage.
If the filehandle we are closing corresponds to a standard handle,
we must protect against these dup2'ed handles in file_cleanup and
invalidate the corresponding StdHandle entries, or they may point
(in the future) to a newly reused handle identifier.
Why testfile.c thinks it can close a std handle and then simply
obtain it again is beyond me.
Revision Changes Path
1.112 +15 -0 apr/file_io/win32/open.c
Index: open.c
===================================================================
RCS file: /home/cvs/apr/file_io/win32/open.c,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -r1.111 -r1.112
--- open.c 29 Oct 2002 01:28:32 -0000 1.111
+++ open.c 28 Dec 2002 20:29:12 -0000 1.112
@@ -264,6 +264,21 @@
apr_status_t flush_rv = APR_SUCCESS;
if (file->filehand != INVALID_HANDLE_VALUE) {
+
+ /* In order to avoid later segfaults with handle 'reuse',
+ * we must protect against the case that a dup2'ed handle
+ * is being closed, and invalidate the corresponding StdHandle
+ */
+ if (file->filehand == GetStdHandle(STD_ERROR_HANDLE)) {
+ SetStdHandle(STD_ERROR_HANDLE, INVALID_HANDLE_VALUE);
+ }
+ else if (file->filehand == GetStdHandle(STD_OUTPUT_HANDLE)) {
+ SetStdHandle(STD_OUTPUT_HANDLE, INVALID_HANDLE_VALUE);
+ }
+ else if (file->filehand == GetStdHandle(STD_INPUT_HANDLE)) {
+ SetStdHandle(STD_INPUT_HANDLE, INVALID_HANDLE_VALUE);
+ }
+
if (file->buffered) {
flush_rv = apr_file_flush((apr_file_t *)thefile);
}