From 144f59abdd8999eac2aea2b130a49e64ef354646 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Thu, 14 Jul 2011 11:10:13 +0000 Subject: [PATCH] Fix memory leak: submenus were never deleted because QMenu::clear() only deletes the QActions git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39299 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/Menus.cpp | 11 +++++++++++ src/frontends/qt4/Menus.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index cb4c3d9150..eb4d0b2a86 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -1631,6 +1631,17 @@ void Menu::updateView() } +void Menu::clear() +{ + QList items = actions(); + for (int i = 0; i != items.size(); ++i) { + // QAction::menu() returns 0 if there's no submenu. + delete items.at(i)->menu(); + } + QMenu::clear(); +} + + ///////////////////////////////////////////////////////////////////// // Menus::Impl definition and implementation ///////////////////////////////////////////////////////////////////// diff --git a/src/frontends/qt4/Menus.h b/src/frontends/qt4/Menus.h index 9513088f6e..59258b7c08 100644 --- a/src/frontends/qt4/Menus.h +++ b/src/frontends/qt4/Menus.h @@ -40,6 +40,9 @@ public: /// ~Menu(); + + /// QMenu::clear() reimplementation to handle the deletion of submenus. + void clear(); private Q_SLOTS: ///