diff --git a/pcbnew/tools/conditional_menu.cpp b/pcbnew/tools/conditional_menu.cpp index dad888c163..95954b2169 100644 --- a/pcbnew/tools/conditional_menu.cpp +++ b/pcbnew/tools/conditional_menu.cpp @@ -24,6 +24,15 @@ #include "conditional_menu.h" +CONDITIONAL_MENU::~CONDITIONAL_MENU() +{ + for( std::list::iterator it = m_entries.begin(); it != m_entries.end(); ++it ) + { + if( it->Type() == ENTRY::MENU ) + delete it->Menu(); + } +} + void CONDITIONAL_MENU::AddItem( const TOOL_ACTION& aAction, const SELECTION_CONDITION& aCondition, int aOrder ) diff --git a/pcbnew/tools/conditional_menu.h b/pcbnew/tools/conditional_menu.h index fcef56d15c..68a705c8b1 100644 --- a/pcbnew/tools/conditional_menu.h +++ b/pcbnew/tools/conditional_menu.h @@ -35,6 +35,9 @@ class SELECTION_TOOL; class CONDITIONAL_MENU { public: + CONDITIONAL_MENU() {} + ~CONDITIONAL_MENU(); + ///> Constant to indicate that we do not care about an ENTRY location in the menu. static const int ANY_ORDER = -1; @@ -54,7 +57,8 @@ public: /** * Function AddMenu() * - * Adds a submenu to the menu. + * Adds a submenu to the menu. CONDITIONAL_MENU takes ownership of the added menu, so it will + * be freed when the CONDITIONAL_MENU object is destroyed. * @param aMenu is the submenu to be added. * @param aLabel is the label of added submenu. * @param aExpand determines if the added submenu items should be added as individual items