Skip to content

Commit 1d0365d

Browse files
authored
Fix: Prevent duplicate close events when closing profile tabs (#8473)
#### Brief overview of PR changes/additions Fixed an issue where closing a profile tab would trigger the close event handler twice, causing duplicate debug messages and potentially leading to crashes during profile shutdown. The fix adds a guard at the beginning of `TMainConsole::closeEvent()` to prevent re-entry during widget destruction, and ensures the `mEnableClose` flag is properly set in all close paths. #### Motivation for adding to Mudlet When closing a profile tab, users would see duplicate debug output: - `TMainConsole::closeEvent(...) INFO - received by "ProfileName".` (appears twice) - `mudlet::saveWindowLayout() - Already-Saved: true` (appears twice) More critically, this duplicate event processing was linked to a reported segmentation fault in `TBuffer::~TBuffer()` where the destructor would crash with a null pointer dereference. The double close event was interfering with proper widget destruction order. #### Other info (issues closed, discussion etc) Related to [Discord chat conversation](https://discord.com/channels/283581582550237184/427919962561052673/1435409031748653188) where a crash was reported during profile closure. Changes made: - Added early return guard in `TMainConsole::closeEvent()` when `mEnableClose` is already true - Set `mEnableClose = true` in the forced close path (before return at line 1682) to ensure the flag is set in all code paths - Added detailed comment explaining the guard's purpose
1 parent 0854053 commit 1d0365d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/TMainConsole.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,15 @@ void TMainConsole::showStatistics()
16361636

16371637
void TMainConsole::closeEvent(QCloseEvent* event)
16381638
{
1639+
// Guard against duplicate close events during widget destruction.
1640+
// The first close comes from explicit close(), the second can come
1641+
// from Qt during widget deletion. Processing the event twice can
1642+
// cause crashes in TBuffer destruction.
1643+
if (mEnableClose) {
1644+
event->accept();
1645+
return;
1646+
}
1647+
16391648
qDebug().nospace().noquote() << "TMainConsole::closeEvent(...) INFO - received by \"" << mpHost->getName() << "\".";
16401649
TEvent conCloseEvent{};
16411650
conCloseEvent.mArgumentList.append(qsl("sysExitEvent"));
@@ -1670,6 +1679,7 @@ void TMainConsole::closeEvent(QCloseEvent* event)
16701679
}
16711680
}
16721681
mpHost->waitForProfileSave();
1682+
mEnableClose = true;
16731683
event->accept();
16741684
return;
16751685
}

0 commit comments

Comments
 (0)