Calling loadwallet and unloadwallet in a loop with the GUI leads to the segfault
To reproduce
0# Build
1git checkout cf4cb28efcf80c018a7f070c671f43cd172dbd86
2make
0# Start gui
1src/qt/bitcoin-qt -regtest -debug=1 -server=1 -printtoconsole
0# Create test wallet
1src/bitcoin-cli -regtest createwallet test
2src/bitcoin-cli -regtest unloadwallet test
0# Trigger segfault
1while src/bitcoin-cli -regtest loadwallet test && src/bitcoin-cli -regtest unloadwallet test; do true; done
Expected behavior
No segfault
Actual behavior
Segfault
Additional information
Stack trace
0Thread 1 "bitcoin-qt" received signal SIGSEGV, Segmentation fault.
10x00007ffff6cd2b7b in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
2(gdb) bt
3[#0](/bitcoin-bitcoin/0/) 0x00007ffff6cd2b7b in () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
4[#1](/bitcoin-bitcoin/1/) 0x00007ffff6cd3512 in QHeaderView::setSectionResizeMode(int, QHeaderView::ResizeMode) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
5[#2](/bitcoin-bitcoin/2/) 0x000055555563f40a in GUIUtil::TableViewLastColumnResizingFixer::setViewHeaderResizeMode(int, QHeaderView::ResizeMode) (this=
6 0x5555583468b0, logicalIndex=-2, resizeMode=QHeaderView::Interactive) at qt/guiutil.cpp:456
7[#3](/bitcoin-bitcoin/3/) 0x000055555563f838 in GUIUtil::TableViewLastColumnResizingFixer::TableViewLastColumnResizingFixer(QTableView*, int, int, QObject*) (this=0x5555583468b0, table=0x555558168150, lastColMinimumWidth=120, allColsMinimumWidth=23, parent=0x5555581520e0) at qt/guiutil.cpp:549
8[#4](/bitcoin-bitcoin/4/) 0x00005555557d6677 in TransactionView::setModel(WalletModel*) (this=0x5555581520e0, _model=0x7fff94001540) at qt/transactionview.cpp:235
9[#5](/bitcoin-bitcoin/5/) 0x0000555555728aef in WalletView::setWalletModel(WalletModel*) (this=0x555557fc0a30, _walletModel=0x7fff94001540) at qt/walletview.cpp:103
10[#6](/bitcoin-bitcoin/6/) 0x00005555556faf1e in WalletFrame::addWallet(WalletModel*) (this=0x555557078120, walletModel=0x7fff94001540) at qt/walletframe.cpp:54
11[#7](/bitcoin-bitcoin/7/) 0x00005555556127f6 in BitcoinGUI::addWallet(WalletModel*) (this=0x555556e85890, walletModel=0x7fff94001540) at qt/bitcoingui.cpp:637
12[#8](/bitcoin-bitcoin/8/) 0x0000555555624456 in QtPrivate::FunctorCall<QtPrivate::IndexesList<0>, QtPrivate::List<WalletModel*>, void, void (BitcoinGUI::*)(WalletModel*)>::call(void (BitcoinGUI::*)(WalletModel*), BitcoinGUI*, void**) (f=
13 (void (BitcoinGUI::*)(BitcoinGUI * const, WalletModel *)) 0x5555556127b0 <BitcoinGUI::addWallet(WalletModel*)>, o=0x555556e85890, arg=0x7fff957a43b0)
14 at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:136
15[#9](/bitcoin-bitcoin/9/) 0x0000555555624395 in QtPrivate::FunctionPointer<void (BitcoinGUI::*)(WalletModel*)>::call<QtPrivate::List<WalletModel*>, void>(void (BitcoinGUI::*)(WalletModel*), BitcoinGUI*, void**) (f=
16 (void (BitcoinGUI::*)(BitcoinGUI * const, WalletModel *)) 0x5555556127b0 <BitcoinGUI::addWallet(WalletModel*)>, o=0x555556e85890, arg=0x7fff957a43b0)
17 at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:169
18[#10](/bitcoin-bitcoin/10/) 0x0000555555624263 in QtPrivate::QSlotObject<void (BitcoinGUI::*)(WalletModel*), QtPrivate::List<WalletModel*>, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) (which=1, this_=0x555556cd4fd0, r=0x555556e85890, a=0x7fff957a43b0, ret=0x0)
19 at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject_impl.h:120
20[#11](/bitcoin-bitcoin/11/) 0x00007ffff5d2a0c2 in QObject::event(QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
21[#12](/bitcoin-bitcoin/12/) 0x00007ffff6ab775b in QWidget::event(QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
22[#13](/bitcoin-bitcoin/13/) 0x00007ffff6bcac6b in QMainWindow::event(QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
23[#14](/bitcoin-bitcoin/14/) 0x00007ffff6a7883c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
24[#15](/bitcoin-bitcoin/15/) 0x00007ffff6a80104 in QApplication::notify(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
25[#16](/bitcoin-bitcoin/16/) 0x00007ffff5cfa8d8 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
26[#17](/bitcoin-bitcoin/17/) 0x00007ffff5cfd04d in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
27[#18](/bitcoin-bitcoin/18/) 0x00007ffff5d54263 in () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
28[#19](/bitcoin-bitcoin/19/) 0x00007ffff1a08417 in g_main_context_dispatch () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
29[#20](/bitcoin-bitcoin/20/) 0x00007ffff1a08650 in () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
30[#21](/bitcoin-bitcoin/21/) 0x00007ffff1a086dc in g_main_context_iteration () at /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
31[#22](/bitcoin-bitcoin/22/) 0x00007ffff5d5388f in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
32[#23](/bitcoin-bitcoin/23/) 0x00007ffff5cf890a in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
33[#24](/bitcoin-bitcoin/24/) 0x00007ffff5d019b4 in QCoreApplication::exec() () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
34[#25](/bitcoin-bitcoin/25/) 0x00005555555f6482 in GuiMain(int, char**) (argc=5, argv=0x7fffffffd418) at qt/bitcoin.cpp:586
35[#26](/bitcoin-bitcoin/26/) 0x00005555555f0e5f in main(int, char**) (argc=5, argv=0x7fffffffd418) at qt/main.cpp:19
This is caused by WalletModel pointer being used after it is deleted. Issue was originally reported #18338 (comment)