Summary
AttachProcessDialog is allocated on the heap but never freed in ui/ui.cpp. The dialog owns a ProcessListWidget which holds a DbgRef<DebuggerController>, causing the controller to also leak.
Root Cause
In ui/ui.cpp (around line 858), the attach action creates the dialog with new but never deletes it:
auto dialog = new AttachProcessDialog(context->mainWindow(), controller);
if (dialog->exec() != QDialog::Accepted)
return;
uint32_t pid = dialog->GetSelectedPid();
Unlike AdapterSettingsDialog which sets Qt::WA_DeleteOnClose in its constructor, AttachProcessDialog has no cleanup mechanism.
Stack trace from leak detector
Possible leak of BinaryNinjaDebuggerAPI::DebuggerController, referenced at:
0 libdebuggerui.dylib ProcessListWidget::ProcessListWidget(QWidget*, ...) + 164
1 libdebuggerui.dylib AttachProcessDialog::AttachProcessDialog(QWidget*, ...) + 312
2 libdebuggerui.dylib GlobalDebuggerUI::SetupMenu(UIContext*)::$_23 + 636
Fix
Add dialog->deleteLater() after the last use of the dialog to ensure proper cleanup.
Related
Identified by @bdash in #1042 (comment)
Summary
AttachProcessDialogis allocated on the heap but never freed inui/ui.cpp. The dialog owns aProcessListWidgetwhich holds aDbgRef<DebuggerController>, causing the controller to also leak.Root Cause
In
ui/ui.cpp(around line 858), the attach action creates the dialog withnewbut never deletes it:Unlike
AdapterSettingsDialogwhich setsQt::WA_DeleteOnClosein its constructor,AttachProcessDialoghas no cleanup mechanism.Stack trace from leak detector
Fix
Add
dialog->deleteLater()after the last use of the dialog to ensure proper cleanup.Related
Identified by @bdash in #1042 (comment)