From ab1fb5350595bcc80073b8ff8140ad09f4c01597 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Thu, 2 Feb 2012 16:58:13 +0000 Subject: [PATCH] * syscalls.cc (close_all_files): Use cygheap_fdget to manipulate fhandler. Use debug_only_printf. --- winsup/cygwin/ChangeLog | 5 +++++ winsup/cygwin/syscalls.cc | 28 ++++++++++++++-------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 60ce099ed..a6c4ae6a1 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +2012-02-02 Christopher Faylor + + * syscalls.cc (close_all_files): Use cygheap_fdget to manipulate + fhandler. Use debug_only_printf. + 2012-02-02 Corinna Vinschen Fix memory and handle leaks due to fdopendir: diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 3ed0f4f95..a14774e1a 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -90,23 +90,23 @@ close_all_files (bool norelease) semaphore::terminate (); - fhandler_base *fh; HANDLE h = NULL; for (int i = 0; i < (int) cygheap->fdtab.size; i++) - if ((fh = cygheap->fdtab[i]) != NULL) - { -#ifdef DEBUGGING - debug_printf ("closing fd %d", i); -#endif - if (i == 2) - DuplicateHandle (GetCurrentProcess (), fh->get_output_handle (), - GetCurrentProcess (), &h, - 0, false, DUPLICATE_SAME_ACCESS); - fh->close_with_arch (); - if (!norelease) - cygheap->fdtab.release (i); - } + { + cygheap_fdget cfd (i); + if (cfd >= 0) + { + debug_only_printf ("closing fd %d", i); + if (i == 2) + DuplicateHandle (GetCurrentProcess (), cfd->get_output_handle (), + GetCurrentProcess (), &h, + 0, false, DUPLICATE_SAME_ACCESS); + cfd->close_with_arch (); + if (!norelease) + cfd.release (); + } + } if (!have_execed && cygheap->ctty) cygheap->close_ctty ();