Skip to content

Commit

Permalink
gui: fix crash on selecting "Mask values" in transaction view
Browse files Browse the repository at this point in the history
This commits fixes a crash bug that can be caused with the following steps:
- change to the "Transactions" view
- right-click on an arbitrary transaction -> "Show transaction details"
- close the transaction detail window again
- select "Settings" -> "Mask values"

The problem is that the list of opened dialogs, tracked in the member
variable `m_opened_dialogs`, is only ever appended with newly opened
transaction detail dialog pointers, but never removed. This leads to
dangling pointers in the list, and if the "Mask values" menu item is
selected, a crash is caused in the course of trying to close the opened
transaction detail dialogs (see `closeOpenedDialogs()` method). Fix this
by removing a pointer of the list if the corresponding widget is
destroyed.
  • Loading branch information
theStack committed Oct 30, 2023
1 parent 4458ae8 commit 02863e3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/qt/transactiondescdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <qt/guiutil.h>
#include <qt/transactiontablemodel.h>
#include <qt/transactionview.h>

#include <QModelIndex>

Expand All @@ -24,5 +25,7 @@ TransactionDescDialog::TransactionDescDialog(const QModelIndex &idx, QWidget *pa

TransactionDescDialog::~TransactionDescDialog()
{
TransactionView *transactionView = static_cast<TransactionView*>(this->parentWidget());
transactionView->removeOpenedDialog(this);
delete ui;
}
7 changes: 6 additions & 1 deletion src/qt/transactionview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ void TransactionView::showDetails()
QModelIndexList selection = transactionView->selectionModel()->selectedRows();
if(!selection.isEmpty())
{
TransactionDescDialog *dlg = new TransactionDescDialog(selection.at(0));
TransactionDescDialog *dlg = new TransactionDescDialog(selection.at(0), /*parent=*/this);
dlg->setAttribute(Qt::WA_DeleteOnClose);
m_opened_dialogs.append(dlg);
dlg->show();
Expand Down Expand Up @@ -652,6 +652,11 @@ void TransactionView::updateWatchOnlyColumn(bool fHaveWatchOnly)
transactionView->setColumnHidden(TransactionTableModel::Watchonly, !fHaveWatchOnly);
}

void TransactionView::removeOpenedDialog(TransactionDescDialog* dlg)
{
m_opened_dialogs.removeOne(dlg);
}

void TransactionView::closeOpenedDialogs()
{
// close all dialogs opened from this view
Expand Down
1 change: 1 addition & 0 deletions src/qt/transactionview.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public Q_SLOTS:
void changedAmount();
void changedSearch();
void exportClicked();
void removeOpenedDialog(TransactionDescDialog*);
void closeOpenedDialogs();
void focusTransaction(const QModelIndex&);
void focusTransaction(const uint256& txid);
Expand Down

0 comments on commit 02863e3

Please sign in to comment.