From c219d8bdbbb2b65d715175e83cd8b8f569f6c521 Mon Sep 17 00:00:00 2001 From: Basile Clement Date: Tue, 18 Mar 2025 03:54:16 +0100 Subject: [PATCH] hotfix: Remove menus when closing game (#5744) Version of #5740 that doesn't leave freed `QMenu`s lying around. --- cockatrice/src/client/tabs/tab_supervisor.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cockatrice/src/client/tabs/tab_supervisor.cpp b/cockatrice/src/client/tabs/tab_supervisor.cpp index 8ba5d791a..632eae06d 100644 --- a/cockatrice/src/client/tabs/tab_supervisor.cpp +++ b/cockatrice/src/client/tabs/tab_supervisor.cpp @@ -256,6 +256,12 @@ void TabSupervisor::closeEvent(QCloseEvent *event) QSet gameTabsToRemove; for (auto it = gameTabs.begin(), end = gameTabs.end(); it != end; ++it) { if (it.value()->close()) { + // Hotfix: the tab owns the `QMenu`s so they need to be cleared, + // otherwise we end up with use-after-free bugs. + if (it.value() == currentWidget()) { + emit setMenu(); + } + gameTabsToRemove.insert(it.key()); } else { event->ignore();