From a600fba538bf3ffea4bbc49f2a6023d26a316028 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 5 Jul 2026 10:20:18 +0200 Subject: [PATCH] fix(AGraph): unref transient GtkBuilder on all menu-build paths The GtkBuilder created for menu construction was never unref'd on any path (success or throw), leaking one builder per graph module with a menu. Unref on each throw and at the end, and take an explicit ref on menu_ so it survives dropping the builder (mirrors ALabel). --- src/AGraph.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/AGraph.cpp b/src/AGraph.cpp index ea1f754d..b0dd5f02 100644 --- a/src/AGraph.cpp +++ b/src/AGraph.cpp @@ -79,13 +79,17 @@ AGraph::AGraph(const Json::Value& config, const std::string& name, const std::st // Make the GtkBuilder and check for errors in his parsing if (gtk_builder_add_from_string(builder, fileContent.str().c_str(), -1, nullptr) == 0U) { + g_object_unref(builder); throw std::runtime_error("Error found in the file " + menuFile); } menu_ = gtk_builder_get_object(builder, "menu"); if (menu_ == nullptr) { + g_object_unref(builder); throw std::runtime_error("Failed to get 'menu' object from GtkBuilder"); } + // Keep the menu alive after dropping the transient GtkBuilder. + g_object_ref(menu_); submenus_ = std::map(); menuActionsMap_ = std::map(); @@ -98,6 +102,7 @@ AGraph::AGraph(const Json::Value& config, const std::string& name, const std::st g_signal_connect(submenus_[key], "activate", G_CALLBACK(handleGtkMenuEvent), (gpointer)menuActionsMap_[key].c_str()); } + g_object_unref(builder); } catch (std::runtime_error& e) { spdlog::warn("Error while creating the menu : {}. Menu popup not activated.", e.what()); }