This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA/commit/procfs] /proc/.../map file descriptor leak


Hello,

This is on sparc-solaris.  I was trying to reproduce another error
that our testsuite occasionally reports (without much success :-().

I noticed while running the test repeatedly within the same debugger
process (that is: repeatedly doing "run; [...]; kill" instead of
starting a new debugger every time) that it would eventually cause
another error in the debugger. The debugger would be telling us that
it is unable to find a given thread in the procinfo list. In other
words, the debugger received an event for LWP=1 and then failed
to create the assocated thread element in the procinfo list.  After some
investgation, it turned out that this was because we were unable to open
the associated lwp file in the /proc filesystem, and that was because we
ran out of file descriptors!

Digging further, I found that we leak the file descriptor created
when opening the procfs map file. we create a cleanup routine to make
sure that the associated file descriptor gets closed, but we never
call the cleanup.

gdb/ChangeLog:

        * procfs.c (iterate_over_mappings): Call do_cleanups before
        returning.

Fixed thusly. Seems fairly straightforward, except that the cleanup
is only really needed when NEW_PROC_API is defined (basically, Solaris
except old versions).  But I think that #ifdef code is ugly, so I made
the cleanup run regardless...

I'll commit in a couple of days pending feedback...

---
 gdb/procfs.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/gdb/procfs.c b/gdb/procfs.c
index 871dd47..2a253a1 100644
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -5217,6 +5217,7 @@ iterate_over_mappings (procinfo *pi, find_memory_region_ftype child_func,
   int funcstat;
   int map_fd;
   int nmap;
+  struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
 #ifdef NEW_PROC_API
   struct stat sbuf;
 #endif
@@ -5254,8 +5255,12 @@ iterate_over_mappings (procinfo *pi, find_memory_region_ftype child_func,
 
   for (prmap = prmaps; nmap > 0; prmap++, nmap--)
     if ((funcstat = (*func) (prmap, child_func, data)) != 0)
-      return funcstat;
+      {
+	do_cleanups (cleanups);
+        return funcstat;
+      }
 
+  do_cleanups (cleanups);
   return 0;
 }
 
-- 
1.7.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]