Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on selecting "Mask values" in transaction view #774

Conversation

theStack
Copy link
Contributor

@theStack theStack commented Oct 30, 2023

This PR 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 menu item "Settings" -> "Mask values"

The problem is that the list of opened dialogs, tracked in the member variable m_opened_dialogs (introduced in #708, commit 4492de1), 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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 30, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK pablomartin4btc, furszy, achow101, hebasto

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

@theStack
Copy link
Contributor Author

Tagging @furszy who signaled interest in this crash bug while talking earlier.

@theStack theStack force-pushed the 202310-gui-fix_mask_values_crash_in_transaction_view branch from 02863e3 to 757e58d Compare October 30, 2023 21:53
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 the pointer from the list if the corresponding widget is
destroyed.
@theStack theStack force-pushed the 202310-gui-fix_mask_values_crash_in_transaction_view branch from 757e58d to e26e665 Compare October 30, 2023 23:29
Copy link
Contributor

@pablomartin4btc pablomartin4btc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

Good catch! I'm the culprit perhaps, I'll take a deeper look at it ASAP!

I took a quick look at the code and LGTM, the original issue with the multiple transaction details dialogs was caught by another reviewer and solved on the original PR #708 but this is a different one.

@theStack
Copy link
Contributor Author

Just force-pushed a much simpler version (only three lines) which avoids the circular dependency and the introduction of new methods. The old version is still available here for reference (or in case the current solution has problems that I'm not aware of): 757e58d

Copy link
Contributor

@pablomartin4btc pablomartin4btc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK e26e665

I easily managed to reproduce the issue in masterfollowing the instructions in the description of the PR (bitcoin-qtcrashes with:Segmentation fault (core dumped)output).

I couldn't reproduce the error anymore while using the new bitcoin-qt version compiled with this branch.

I'd prefer this second approach better. Thank for fixing it!

Copy link
Contributor

@MarnixCroes MarnixCroes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tack e26e665

Copy link
Member

@furszy furszy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also:

diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp
@@ -656,7 +656,7 @@
 {
     // close all dialogs opened from this view
     for (QDialog* dlg : m_opened_dialogs) {
-        dlg->close();
+        if (dlg) dlg->close();
     }
     m_opened_dialogs.clear();
 }

Copy link
Member

@furszy furszy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK e26e665

@theStack
Copy link
Contributor Author

Could also:

diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp
@@ -656,7 +656,7 @@
 {
     // close all dialogs opened from this view
     for (QDialog* dlg : m_opened_dialogs) {
-        dlg->close();
+        if (dlg) dlg->close();
     }
     m_opened_dialogs.clear();
 }

This wouldn't change the behaviour, as a pointer in the m_opened_dialogs list is not set to NULL after the dialog it points to is destroyed. I think it could work if we used guarded pointers like QPointer in the list instead, IIUC (but we don't seem to use them anywhere in our codebase).

@achow101
Copy link
Member

Should this be backported?

@theStack
Copy link
Contributor Author

Should this be backported?

Yes, I think so. The bug first occured with release 25.0 (according to git tag --contains 4492de1be11 in the main repo), so backporting to 25.x and 26.x would make sense.

@achow101
Copy link
Member

ACK e26e665

@pablomartin4btc
Copy link
Contributor

I do agree with @theStack backporting (checked it with the git tag command) since the issue technically is the "conflict" between these 2 lines:

dlg->setAttribute(Qt::WA_DeleteOnClose);
m_opened_dialogs.append(dlg);

The last one (#L533) was added by the #708 (merged in v25 - I wanted to say I'm innocent but no haha), so another way to solve this issue is just by removing #L532, which I've tested and works fine.

@hebasto hebasto changed the title gui: fix crash on selecting "Mask values" in transaction view Fix crash on selecting "Mask values" in transaction view Nov 1, 2023
Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK e26e665, tested on Ubuntu 22.04.

@fanquake
Copy link
Member

fanquake commented Nov 1, 2023

Will backport this once merged.

@hebasto
Copy link
Member

hebasto commented Nov 1, 2023

dlg->setAttribute(Qt::WA_DeleteOnClose);
m_opened_dialogs.append(dlg);

The last one (#L533) was added by the #708 (merged in v25 - I wanted to say I'm innocent but no haha), so another way to solve this issue is just by removing #L532, which I've tested and works fine.

It will still allow to grow the size of m_opened_dialogs unbounded.

The current PR branch tackles with m_opened_dialogs size, which is the optimum solution.

@hebasto hebasto merged commit 04bfe8c into bitcoin-core:master Nov 1, 2023
16 checks passed
@fanquake
Copy link
Member

fanquake commented Nov 1, 2023

Added to bitcoin/bitcoin#28754 for 26.x.

fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Nov 1, 2023
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 the pointer from the list if the corresponding widget is
destroyed.

Github-Pull: bitcoin-core/gui#774
Rebased-From: e26e665
@theStack theStack deleted the 202310-gui-fix_mask_values_crash_in_transaction_view branch November 1, 2023 10:03
fanquake added a commit to bitcoin/bitcoin that referenced this pull request Nov 1, 2023
e4e8479 doc: update manual pages for v26.0rc2 (fanquake)
0b189a9 build: bump version to v26.0rc2 (fanquake)
e097d4c gui: fix crash on selecting "Mask values" in transaction view (Sebastian Falbesoner)
05e8874 guix: update signapple (fanquake)
deccc50 guix: Zip needs to include all files with time as SOURCE_DATE_EPOCH (Andrew Chow)
fe57abd test: add coverage for snapshot chainstate not matching AssumeUTXO parameters (pablomartin4btc)
b761a58 assumeutxo, blockstorage: prevent core dump on invalid hash (pablomartin4btc)
d3ebf6e [test] Test i2p private key constraints (Vasil Dimov)
1f11784 [net] Check i2p private key constraints (dergoegge)
6544ffa bugfix: Mark CNoDestination and PubKeyDestination constructor explicit (MarcoFalke)

Pull request description:

  Backports for v26.0rc2:
  * #28695
  * #28698
  * #28728
  * #28757
  * #28759
  * bitcoin-core/gui#774

ACKs for top commit:
  josibake:
    ACK e4e8479
  hebasto:
    re-ACK e4e8479, only a backport of bitcoin-core/gui#774 added since my [recent](#28754 (review)) review.
  TheCharlatan:
    Re-ACK e4e8479

Tree-SHA512: 4b95afd26b8bf91250cb883423de8b274cefa48dc474734f5900aeb756eee3a6c656116efcfa2caff3c250678c16b70cc6b7a5d840018dc7e2c1e8161622cd61
@fanquake
Copy link
Member

fanquake commented Nov 1, 2023

Pulled this into a branch for 25.x backporting. See bitcoin/bitcoin#28768.

fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Nov 1, 2023
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 the pointer from the list if the corresponding widget is
destroyed.

Github-Pull: bitcoin-core/gui#774
Rebased-From: e26e665
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Dec 11, 2023
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 the pointer from the list if the corresponding widget is
destroyed.

Github-Pull: bitcoin-core/gui#774
Rebased-From: e26e665
fanquake added a commit to bitcoin/bitcoin that referenced this pull request Jan 16, 2024
53bbda5 doc: update release notes for 25.x (fanquake)
31e1e03 test: add regression test for the getrawtransaction segfault (Martin Zumsande)
041228d rpc: fix getrawtransaction segfault (Martin Zumsande)
b86285d gui: fix crash on selecting "Mask values" in transaction view (Sebastian Falbesoner)
c21024f doc: add historical release notes for 25.1 (fanquake)

Pull request description:

  Collecting backports for the 25.x branch. Currently:
  * bitcoin-core/gui#774
  * #29003

ACKs for top commit:
  stickies-v:
    ACK 53bbda5

Tree-SHA512: 9b1ba17cce9de70d20329372ba71225dd930718a1f7db84a7be764dcfbba01c5e466255e7b95433ab6d7559ee8aaa04cc99ee5d1512d91fcc0a8015f1aa4150a
backpacker69 pushed a commit to peercoin/peercoin that referenced this pull request Jun 14, 2024
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 the pointer from the list if the corresponding widget is
destroyed.

Github-Pull: bitcoin-core/gui#774
Rebased-From: e26e665f9f64a962dd56053be817cc953e714847
@bitcoin-core bitcoin-core locked and limited conversation to collaborators Oct 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants