From 3d9b569384e6a7339f1c18fc2786f3cda396f593 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Thu, 28 Dec 2017 23:22:13 -0500 Subject: [PATCH] Debugger: Further work on memory leak hunting. TeamWindow: - Properly delete stack frame selection entries in destructor. TeamDebugger: - The reference to TeamDebugInfo wasn't correctly initialized to own, leading to TeamDebugInfo never being destroyed. FunctionInstance: - Also clear source code reference in destructor. ImageDebugInfo: - Release references to specific infos in destructor. These are acquired on our behalf when loading the image info, but were never released, leading to the latter never being freed. DwarfManager: - Release references to files in destructor. FileManager: - Release entries in various destructors. Somewhat improves the situation in #13800, but is still far from complete, as a thorough review of this nature hasn't ever really been done. --- .../user_interface/gui/team_window/TeamWindow.cpp | 10 ++++++++++ src/kits/debugger/controllers/TeamDebugger.cpp | 2 +- src/kits/debugger/debug_info/FunctionInstance.cpp | 1 + src/kits/debugger/debug_info/ImageDebugInfo.cpp | 8 +++++++- src/kits/debugger/dwarf/DwarfManager.cpp | 4 +++- src/kits/debugger/files/FileManager.cpp | 15 ++++++++++++++- 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp b/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp index 5a82a3b2fa..50f72f92e0 100644 --- a/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp +++ b/src/apps/debugger/user_interface/gui/team_window/TeamWindow.cpp @@ -282,6 +282,16 @@ TeamWindow::~TeamWindow() _SetActiveThread(NULL); delete fFilePanel; + + ThreadStackFrameSelectionEntry* entry + = fThreadSelectionInfoTable->Clear(true); + + while (entry != NULL) { + ThreadStackFrameSelectionEntry* next = entry->next; + delete entry; + entry = next; + } + delete fThreadSelectionInfoTable; if (fActiveSourceWorker > 0) diff --git a/src/kits/debugger/controllers/TeamDebugger.cpp b/src/kits/debugger/controllers/TeamDebugger.cpp index d5b3cda0d7..49f152e90c 100644 --- a/src/kits/debugger/controllers/TeamDebugger.cpp +++ b/src/kits/debugger/controllers/TeamDebugger.cpp @@ -366,7 +366,7 @@ TeamDebugger::Init(DebuggerInterface* interface, thread_id threadID, int argc, fFileManager); if (teamDebugInfo == NULL) return B_NO_MEMORY; - BReference teamDebugInfoReference(teamDebugInfo); + BReference teamDebugInfoReference(teamDebugInfo, true); error = teamDebugInfo->Init(); if (error != B_OK) diff --git a/src/kits/debugger/debug_info/FunctionInstance.cpp b/src/kits/debugger/debug_info/FunctionInstance.cpp index b7398f7887..1ecbd3af71 100644 --- a/src/kits/debugger/debug_info/FunctionInstance.cpp +++ b/src/kits/debugger/debug_info/FunctionInstance.cpp @@ -32,6 +32,7 @@ FunctionInstance::FunctionInstance(ImageDebugInfo* imageDebugInfo, FunctionInstance::~FunctionInstance() { SetFunction(NULL); + SetSourceCode(NULL, FUNCTION_SOURCE_NOT_LOADED); fFunctionDebugInfo->ReleaseReference(); } diff --git a/src/kits/debugger/debug_info/ImageDebugInfo.cpp b/src/kits/debugger/debug_info/ImageDebugInfo.cpp index 2c7c86c69e..88f6cde123 100644 --- a/src/kits/debugger/debug_info/ImageDebugInfo.cpp +++ b/src/kits/debugger/debug_info/ImageDebugInfo.cpp @@ -1,6 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. - * Copyright 2010-2013, Rene Gollent, rene@gollent.com. + * Copyright 2010-2017, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ @@ -27,12 +27,18 @@ ImageDebugInfo::~ImageDebugInfo() { for (int32 i = 0; FunctionInstance* function = fFunctions.ItemAt(i); i++) function->ReleaseReference(); + + for (int32 i = 0; SpecificImageDebugInfo* info = fSpecificInfos.ItemAt(i); + i++) { + info->ReleaseReference(); + } } bool ImageDebugInfo::AddSpecificInfo(SpecificImageDebugInfo* info) { + // NB: on success we take over the caller's reference to the info object return fSpecificInfos.AddItem(info); } diff --git a/src/kits/debugger/dwarf/DwarfManager.cpp b/src/kits/debugger/dwarf/DwarfManager.cpp index 9f36611e8c..9b5a07ebdc 100644 --- a/src/kits/debugger/dwarf/DwarfManager.cpp +++ b/src/kits/debugger/dwarf/DwarfManager.cpp @@ -1,6 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. - * Copyright 2014, Rene Gollent, rene@gollent.com. + * Copyright 2014-2017, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ @@ -25,6 +25,8 @@ DwarfManager::DwarfManager(uint8 addressSize) DwarfManager::~DwarfManager() { + while (DwarfFile* file = fFiles.RemoveHead()) + file->ReleaseReference(); } diff --git a/src/kits/debugger/files/FileManager.cpp b/src/kits/debugger/files/FileManager.cpp index bce3c02db0..fb614f1d97 100644 --- a/src/kits/debugger/files/FileManager.cpp +++ b/src/kits/debugger/files/FileManager.cpp @@ -1,6 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. - * Copyright 2011-2016, Rene Gollent, rene@gollent.com. + * Copyright 2011-2017, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ @@ -118,6 +118,12 @@ public: ~Domain() { + LocatableEntry* entry = fEntries.Clear(true); + while (entry != NULL) { + LocatableEntry* next = entry->fNext; + entry->ReleaseReference(); + entry = next; + } } status_t Init() @@ -555,6 +561,13 @@ FileManager::~FileManager() { delete fTargetDomain; delete fSourceDomain; + + SourceFileEntry* entry = fSourceFiles->Clear(); + while (entry != NULL) { + SourceFileEntry* next = entry->next; + delete entry; + next = entry; + } delete fSourceFiles; }