From 08765fac3f4523883ce44ac938fa0523cfb8bbd6 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Thu, 28 May 2015 03:24:30 +0000 Subject: [PATCH] I finally found the strong reference that was keeping all lldb_private::Process instances from ever destroying themselves: ProcessModID.m_mod_id was holding onto the last stop event with ProcessModID::SetStopEventForLastNaturalStopID(EventSP). This is a bad idea because ProcessEventData contains a strong refereence to the process. This is now fixed by calling ProcessModID::SetStopEventForLastNaturalStopID(EventSP()) to clear this event in Process::SetExitStatus() and in Process::Finalize(). This was the original cause of the file descriptor leaks that would cause the test suite to die after running a few hundred processes since no process would ever get destroyed and the communication channel in ProcessGDBRemote and the ProcessIOHandler would never close their pipes. This process leak was previously worked around by closing the pipes when the communication channel was disconnected. This was found by using "ptr_refs" from the heap.py in the lldb.macosx.heap module. It was able to find all strong references to the Process and helped me to figure out who was holding this extra reference. llvm-svn: 238392 --- lldb/source/Target/Process.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index f0bd9e3..3380d0e 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -874,6 +874,9 @@ Process::Finalize() m_instrumentation_runtimes.clear(); m_next_event_action_ap.reset(); m_stop_info_override_callback = NULL; + // Clear the last natural stop ID since it has a strong + // reference to this process + m_mod_id.SetStopEventForLastNaturalStopID(EventSP()); //#ifdef LLDB_CONFIGURATION_DEBUG // StreamFile s(stdout, false); // EventSP event_sp; @@ -1467,6 +1470,10 @@ Process::SetExitStatus (int status, const char *cstr) m_process_input_reader.reset(); } + // Clear the last natural stop ID since it has a strong + // reference to this process + m_mod_id.SetStopEventForLastNaturalStopID(EventSP()); + SetPrivateState (eStateExited); // Allow subclasses to do some cleanup -- 2.7.4