From 44ede8c9427697e40a9e910d3bd27cbaedf4e3fe Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 2 Apr 2010 09:39:05 -0400 Subject: [PATCH] Squash epic memory leak StThemeNode holds a reference to its parent, but we never released that reference. This could cause us to hold onto whole chains of theme nodes with rather dire memory usage implications. Also move the other g_object_unref into _dispose. https://bugzilla.gnome.org/show_bug.cgi?id=614660 --- src/st/st-theme-node.c | 41 +++++++++++++++++++++++++++++++++++------ src/st/st-widget.c | 1 + 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/st/st-theme-node.c b/src/st/st-theme-node.c index cf6769ac9..d742c6bda 100644 --- a/src/st/st-theme-node.c +++ b/src/st/st-theme-node.c @@ -9,6 +9,7 @@ static void st_theme_node_init (StThemeNode *node); static void st_theme_node_class_init (StThemeNodeClass *klass); +static void st_theme_node_dispose (GObject *object); static void st_theme_node_finalize (GObject *object); static const ClutterColor BLACK_COLOR = { 0, 0, 0, 0xff }; @@ -27,9 +28,43 @@ st_theme_node_class_init (StThemeNodeClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->dispose = st_theme_node_dispose; object_class->finalize = st_theme_node_finalize; } + +static void +st_theme_node_dispose (GObject *gobject) +{ + StThemeNode *node = ST_THEME_NODE (gobject); + + if (node->context) + { + g_object_unref (node->context); + node->context = NULL; + } + + if (node->theme) + { + g_object_unref (node->theme); + node->theme = NULL; + } + + if (node->parent_node) + { + g_object_unref (node->parent_node); + node->parent_node = NULL; + } + + if (node->border_image) + { + g_object_unref (node->border_image); + node->border_image = NULL; + } + + G_OBJECT_CLASS (st_theme_node_parent_class)->dispose (gobject); +} + static void st_theme_node_finalize (GObject *object) { @@ -59,12 +94,6 @@ st_theme_node_finalize (GObject *object) node->font_desc = NULL; } - if (node->border_image) - { - g_object_unref (node->border_image); - node->border_image = NULL; - } - if (node->shadow) { st_shadow_free (node->shadow); diff --git a/src/st/st-widget.c b/src/st/st-widget.c index dba5a040e..75da099fc 100644 --- a/src/st/st-widget.c +++ b/src/st/st-widget.c @@ -253,6 +253,7 @@ st_widget_dispose (GObject *gobject) if (priv->theme_node) { + g_object_run_dispose (G_OBJECT (priv->theme_node)); g_object_unref (priv->theme_node); priv->theme_node = NULL; }