Skip to content

Commit

Permalink
DolphinQt: Properly Delete (Some) Widgets
Browse files Browse the repository at this point in the history
This is not every memory leak, just the ones that were obvious.
  • Loading branch information
mitaclaw committed Apr 30, 2024
1 parent e69486d commit 72aa0ce
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions Source/Core/DolphinQt/CheatSearchWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ void CheatSearchWidget::OnAddressTableContextMenu()
const u32 address = item->data(ADDRESS_TABLE_ADDRESS_ROLE).toUInt();

QMenu* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);

menu->addAction(tr("Show in memory"), [this, address] { emit ShowMemory(address); });
menu->addAction(tr("Add to watch"), this, [this, address] {
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinQt/Config/FilesystemWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ void FilesystemWidget::ShowContextMenu(const QPoint&)
auto* item = m_tree_model->itemFromIndex(selection->selectedIndexes()[0]);

QMenu* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);

EntryType type = item->data(ENTRY_TYPE).value<EntryType>();

Expand Down
2 changes: 2 additions & 0 deletions Source/Core/DolphinQt/Debugger/BranchWatchDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,8 @@ void BranchWatchDialog::OnTableContextMenu(const QPoint& pos)
QModelIndexList index_list = m_table_view->selectionModel()->selectedRows(index.column());

QMenu* const menu = new QMenu;
menu->setAttribute(Qt::WA_DeleteOnClose, true);

menu->addAction(tr("&Delete"), [this, index_list]() { OnTableDelete(std::move(index_list)); });
switch (index.column())
{
Expand Down
4 changes: 4 additions & 0 deletions Source/Core/DolphinQt/Debugger/BreakpointWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ void BreakpointWidget::OnClear()
void BreakpointWidget::OnNewBreakpoint()
{
BreakpointDialog* dialog = new BreakpointDialog(this);
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
SetQWidgetWindowDecorations(dialog);
dialog->exec();
}
Expand All @@ -319,13 +320,15 @@ void BreakpointWidget::OnEditBreakpoint(u32 address, bool is_instruction_bp)
{
auto* dialog =
new BreakpointDialog(this, m_system.GetPowerPC().GetBreakPoints().GetBreakpoint(address));
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
SetQWidgetWindowDecorations(dialog);
dialog->exec();
}
else
{
auto* dialog =
new BreakpointDialog(this, m_system.GetPowerPC().GetMemChecks().GetMemCheck(address));
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
SetQWidgetWindowDecorations(dialog);
dialog->exec();
}
Expand Down Expand Up @@ -387,6 +390,7 @@ void BreakpointWidget::OnContextMenu()
const auto is_memory_breakpoint = selected_item->data(IS_MEMCHECK_ROLE).toBool();

auto* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);

if (!is_memory_breakpoint)
{
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ void CodeViewWidget::ReplaceAddress(u32 address, ReplaceWith replace)
void CodeViewWidget::OnContextMenu()
{
QMenu* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);

const bool running = Core::GetState(m_system) != Core::State::Uninitialized;
const bool paused = Core::GetState(m_system) == Core::State::Paused;
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,7 @@ void MemoryViewWidget::OnContextMenu(const QPoint& pos)
->IsValidAddress(Core::CPUThreadGuard{m_system}, addr);

auto* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);

menu->addAction(tr("Copy Address"), this, [this, addr] { OnCopyAddress(addr); });

Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinQt/Debugger/RegisterWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ void RegisterWidget::OnItemChanged(QTableWidgetItem* item)
void RegisterWidget::ShowContextMenu()
{
QMenu* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);

auto* raw_item = m_table->currentItem();

Expand Down
2 changes: 2 additions & 0 deletions Source/Core/DolphinQt/Debugger/ThreadWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ void ThreadWidget::ShowContextMenu(QTableWidget* table)
return;

QMenu* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);

const QString watch_name = QStringLiteral("thread_context_%1").arg(addr, 8, 16, QLatin1Char('0'));
menu->addAction(tr("Add &breakpoint"), this, [this, addr] { emit RequestBreakpoint(addr); });
menu->addAction(tr("Add memory breakpoint"), this,
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinQt/Debugger/WatchWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ void WatchWidget::OnSave()
void WatchWidget::ShowContextMenu()
{
QMenu* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);

if (!m_table->selectedItems().empty())
{
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinQt/GameList/GameList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ void GameList::ShowContextMenu(const QPoint&)
return;

QMenu* menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose, true);

if (HasMultipleSelected())
{
Expand Down
4 changes: 4 additions & 0 deletions Source/Core/DolphinQt/NetPlay/NetPlayBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,13 @@ void NetPlayBrowser::accept()

SetQWidgetWindowDecorations(dialog);
if (dialog->exec() != QDialog::Accepted)
{
delete dialog;
return;
}

const std::string password = dialog->textValue().toStdString();
delete dialog;

auto decrypted_id = session.DecryptID(password);

Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinQt/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void Updater::OnUpdateAvailable(const NewVersionInformation& info)

std::optional<int> choice = RunOnObject(m_parent, [&] {
QDialog* dialog = new QDialog(m_parent);
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
dialog->setWindowTitle(tr("Update available"));
dialog->setWindowFlags(dialog->windowFlags() & ~Qt::WindowContextHelpButtonHint);

Expand Down

0 comments on commit 72aa0ce

Please sign in to comment.