Skip to content

AttachProcessDialog leaks when the user opens it from the menu, not the controls widget #1061

@xusheng6

Description

@xusheng6

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)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions