From 6c564607770479173967b9a74926cbe1c4bc109e Mon Sep 17 00:00:00 2001
From: Andy Shaw <andy.shaw@digia.com>
Date: Thu, 30 Aug 2012 22:40:01 +0200
Subject: Prevent a crash when a merged action is removed
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

If a merged action is removed then a crash can occur if it is readded
later.

Task-number: QTBUG-24917
Change-Id: I43dcde3f40950fafc33d976e861a90fe1c38d061
Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
---
 src/gui/widgets/qmenu_mac.mm | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/gui/widgets/qmenu_mac.mm b/src/gui/widgets/qmenu_mac.mm
index f333ce5..325f8e4 100644
--- a/src/gui/widgets/qmenu_mac.mm
+++ b/src/gui/widgets/qmenu_mac.mm
@@ -1504,6 +1504,16 @@ QMenuPrivate::QMacMenuPrivate::removeAction(QMacMenuAction *action)
                 && action->menuItem != [loader preferencesMenuItem]) {
                 [[action->menuItem menu] removeItem:action->menuItem];
             }
+            if (QMenuMergeList *list = mergeMenuItemsHash.value(action->menu)) {
+                int i = 0;
+                while (i < list->size()) {
+                    const QMenuMergeItem &item = list->at(i);
+                    if (item.action == action)
+                        list->removeAt(i);
+                    else
+                        ++i;
+                }
+            }
         }
     } else {
         [[action->menuItem menu] removeItem:action->menuItem];
-- 
cgit v0.12