From c3ac0a72a603f01b86fba870af14cff22f1db48c Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 11 Sep 2018 21:03:19 -0400 Subject: [PATCH] BMenuItem: Remove ourselves from the super menu on destruct. This fixes the (intermittently) crashing test added in the previous commit, and should also fix #12024 and #14348. Note that this is a slight behavioral departure from BeOS, though since BeOS crashed when this was done previously, it shouldn't cause any other problems. Change-Id: I90b6132ff7741b8d6cb601375a9b11fc3ffacb40 Reviewed-on: https://review.haiku-os.org/541 Reviewed-by: waddlesplash --- docs/user/interface/MenuItem.dox | 4 +++- src/kits/interface/MenuItem.cpp | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/user/interface/MenuItem.dox b/docs/user/interface/MenuItem.dox index 147a506296..cb2510fc3f 100644 --- a/docs/user/interface/MenuItem.dox +++ b/docs/user/interface/MenuItem.dox @@ -115,7 +115,9 @@ \fn BMenuItem::~BMenuItem() \brief Destructor. - Also frees the memory used by the label or submenu. + If this item is attached to a menu, it will be removed from it. + + Also destroys the label and submenu. \since BeOS R3 */ diff --git a/src/kits/interface/MenuItem.cpp b/src/kits/interface/MenuItem.cpp index c28ce3f732..2d49398c01 100644 --- a/src/kits/interface/MenuItem.cpp +++ b/src/kits/interface/MenuItem.cpp @@ -181,6 +181,9 @@ BMenuItem::Archive(BMessage* data, bool deep) const BMenuItem::~BMenuItem() { + if (fSuper != NULL) + fSuper->RemoveItem(this); + free(fLabel); delete fSubmenu; }