summaryrefslogtreecommitdiff
path: root/gtk2_ardour/ardour_ui.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2019-03-07 17:02:12 +0100
committerRobin Gareus <robin@gareus.org>2019-03-07 23:50:50 +0100
commit7b96fa1c5e99e054f43ca3272d21ae955bfa3443 (patch)
tree67f2e5efd9ce1890ad3a6444cb114341576d26d3 /gtk2_ardour/ardour_ui.cc
parent12a415f0772048f8a38a66a037b024223bc7bbc0 (diff)
Fix some Gtk::Menu memory leaks
A Gtk::manage()d widget will be deleted when its parent container is destroyed. Top-level context menus are not inside a container and hence need to be manually deallocated. The solution here is to use a shared Gtk::Menu pointer that is centrally de/re-allocated. This works because the GUI is single-threaded and at most one context menu is visible at a time.
Diffstat (limited to 'gtk2_ardour/ardour_ui.cc')
-rw-r--r--gtk2_ardour/ardour_ui.cc15
1 files changed, 14 insertions, 1 deletions
diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc
index 6e8ca92d6c..c9a5ac8e1a 100644
--- a/gtk2_ardour/ardour_ui.cc
+++ b/gtk2_ardour/ardour_ui.cc
@@ -287,6 +287,7 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir)
, _was_dirty (false)
, _mixer_on_top (false)
, _initial_verbose_plugin_scan (false)
+ , _shared_popup_menu (0)
, secondary_clock_spacer (0)
, auto_input_button (ArdourButton::led_default_elements)
, time_info_box (0)
@@ -868,6 +869,7 @@ ARDOUR_UI::~ARDOUR_UI ()
delete rc_option_editor; rc_option_editor = 0; // failed to wrap object warning
delete nsm; nsm = 0;
delete gui_object_state; gui_object_state = 0;
+ delete _shared_popup_menu ; _shared_popup_menu = 0;
delete main_window_visibility;
FastMeter::flush_pattern_cache ();
ArdourFader::flush_pattern_cache ();
@@ -5433,7 +5435,7 @@ ARDOUR_UI::popup_editor_meter_menu (GdkEventButton* ev)
{
using namespace Gtk::Menu_Helpers;
- Gtk::Menu* m = manage (new Menu);
+ Gtk::Menu* m = shared_popup_menu ();
MenuList& items = m->items ();
RadioMenuItem::Group group;
@@ -6024,3 +6026,14 @@ ARDOUR_UI::monitor_mono ()
Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Monitor"), "monitor-mono");
_monitor->set_mono (tact->get_active());
}
+
+Gtk::Menu*
+ARDOUR_UI::shared_popup_menu ()
+{
+ ENSURE_GUI_THREAD (*this, &ARDOUR_UI::shared_popup_menu, ignored);
+
+ assert (!_shared_popup_menu || !_shared_popup_menu->is_visible());
+ delete _shared_popup_menu;
+ _shared_popup_menu = new Gtk::Menu;
+ return _shared_popup_menu;
+}