[Xfce4-commits] <xfce4-taskmanager:master> Plug a dynamic leak

Mike Massonnet noreply at xfce.org
Wed Jun 2 01:06:01 CEST 2010


Updating branch refs/heads/master
         to 06921c3ac131cd3a683ff2d64e2d1f3fd9985635 (commit)
       from b4ad15b0090555e54b7d03b28ec4950e927eef8a (commit)

commit 06921c3ac131cd3a683ff2d64e2d1f3fd9985635
Author: Mike Massonnet <mmassonnet at xfce.org>
Date:   Wed Jun 2 00:59:49 2010 +0200

    Plug a dynamic leak
    
    A leak occured in the timer code, and thus the memory was growing over
    time. Cf. src/task-manager.c(model_update_tree_iter), the old_state
    variable was not free'd.
    
    Plugged other static leaks at the same time.

 src/main.c              |    3 +++
 src/process-statusbar.c |    9 +++++++++
 src/process-tree-view.c |   30 ++++++++++++++++++++++++++++++
 src/process-window.c    |    8 ++++++--
 src/settings.c          |    5 +++--
 src/task-manager.c      |    1 +
 6 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/src/main.c b/src/main.c
index bd22d40..9fe8e5f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -140,6 +140,9 @@ int main (int argc, char *argv[])
 	if (timeout > 0)
 		g_source_remove (timeout);
 	g_object_unref (window);
+	g_object_unref (status_icon);
+	g_object_unref (task_manager);
+	g_object_unref (settings);
 
 	return 0;
 }
diff --git a/src/process-statusbar.c b/src/process-statusbar.c
index ad41051..8535728 100644
--- a/src/process-statusbar.c
+++ b/src/process-statusbar.c
@@ -51,6 +51,7 @@ struct _XtmProcessStatusbar
 };
 G_DEFINE_TYPE (XtmProcessStatusbar, xtm_process_statusbar, GTK_TYPE_STATUSBAR)
 
+static void	xtm_process_statusbar_finalize			(GObject *object);
 static void	xtm_process_statusbar_set_property		(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
 
 
@@ -60,6 +61,7 @@ xtm_process_statusbar_class_init (XtmProcessStatusbarClass *klass)
 {
 	GObjectClass *class = G_OBJECT_CLASS (klass);
 	xtm_process_statusbar_parent_class = g_type_class_peek_parent (klass);
+	class->finalize = xtm_process_statusbar_finalize;
 	class->set_property = xtm_process_statusbar_set_property;
 	g_object_class_install_property (class, PROP_CPU,
 		g_param_spec_float ("cpu", "CPU", "CPU usage", 0, 100, 0, G_PARAM_CONSTRUCT|G_PARAM_WRITABLE));
@@ -116,6 +118,13 @@ xtm_process_statusbar_init (XtmProcessStatusbar *statusbar)
 	gtk_widget_show_all (hbox);
 }
 
+static void
+xtm_process_statusbar_finalize (GObject *object)
+{
+	g_object_unref (XTM_PROCESS_STATUSBAR (object)->settings);
+	G_OBJECT_CLASS (xtm_process_statusbar_parent_class)->finalize (object);
+}
+
 static gchar *
 rounded_float_value (gfloat value, XtmSettings *settings)
 {
diff --git a/src/process-tree-view.c b/src/process-tree-view.c
index afc761d..dc6c9e4 100644
--- a/src/process-tree-view.c
+++ b/src/process-tree-view.c
@@ -55,6 +55,8 @@ struct _XtmProcessTreeView
 };
 G_DEFINE_TYPE (XtmProcessTreeView, xtm_process_tree_view, GTK_TYPE_TREE_VIEW)
 
+static void		xtm_process_tree_view_finalize			(GObject *object);
+
 static gboolean		treeview_clicked				(XtmProcessTreeView *treeview, GdkEventButton *event);
 static void		columns_changed					(XtmProcessTreeView *treeview);
 static void		read_columns_positions				(XtmProcessTreeView *treeview);
@@ -69,7 +71,9 @@ static void		settings_changed				(GObject *object, GParamSpec *pspec, XtmProcess
 static void
 xtm_process_tree_view_class_init (XtmProcessTreeViewClass *klass)
 {
+	GObjectClass *class = G_OBJECT_CLASS (klass);
 	xtm_process_tree_view_parent_class = g_type_class_peek_parent (klass);
+	class->finalize = xtm_process_tree_view_finalize;
 }
 
 static void
@@ -85,6 +89,7 @@ xtm_process_tree_view_init (XtmProcessTreeView *treeview)
 	{
 		gchar *uid_name;
 		get_owner_uid (&treeview->owner_uid, &uid_name);
+		g_free (uid_name);
 		g_object_get (treeview->settings, "show-all-processes", &treeview->show_all_processes_cached, NULL);
 	}
 
@@ -205,6 +210,31 @@ xtm_process_tree_view_init (XtmProcessTreeView *treeview)
 	g_signal_connect (treeview, "button-press-event", G_CALLBACK (treeview_clicked), NULL);
 }
 
+static void
+xtm_process_tree_view_finalize (GObject *object)
+{
+	XtmProcessTreeView *treeview = XTM_PROCESS_TREE_VIEW (object);
+
+	if (GTK_IS_TREE_MODEL (treeview->model))
+	{
+		g_object_unref (treeview->model);
+		treeview->model = NULL;
+	}
+
+	if (GTK_IS_TREE_MODEL (treeview->model_filter))
+	{
+		g_object_unref (treeview->model_filter);
+		treeview->model_filter = NULL;
+	}
+
+	if (XTM_IS_SETTINGS (treeview->settings))
+	{
+		g_object_unref (treeview->settings);
+	}
+
+	G_OBJECT_CLASS (xtm_process_tree_view_parent_class)->finalize (object);
+}
+
 /**
  * Helper functions
  */
diff --git a/src/process-window.c b/src/process-window.c
index 08d1462..03089ad 100644
--- a/src/process-window.c
+++ b/src/process-window.c
@@ -147,10 +147,14 @@ xtm_process_window_finalize (GObject *object)
 				"sort-column-id", sort_column_id, "sort-type", sort_type, NULL);
 	}
 
+	if (GTK_IS_TREE_VIEW (priv->treeview))
+		gtk_widget_destroy (priv->treeview);
+
+	if (GTK_IS_STATUSBAR (priv->statusbar))
+		gtk_widget_destroy (priv->statusbar);
+
 	if (XTM_IS_SETTINGS (priv->settings))
-	{
 		g_object_unref (priv->settings);
-	}
 }
 
 /**
diff --git a/src/settings.c b/src/settings.c
index 37daf3d..6550f61 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -198,7 +198,7 @@ xtm_settings_load_settings (XtmSettings *settings)
 
 	if (g_key_file_load_from_file (rc, filename, G_KEY_FILE_NONE, NULL))
 	{
-		const gchar *string;
+		gchar *string;
 		GValue dst = {0};
 		GValue src = {0};
 		GParamSpec **specs;
@@ -215,7 +215,8 @@ xtm_settings_load_settings (XtmSettings *settings)
 				continue;
 
 			g_value_init (&src, G_TYPE_STRING);
-			g_value_set_static_string (&src, string);
+			g_value_set_string (&src, string);
+			g_free (string);
 
 			if (spec->value_type == G_TYPE_STRING)
 			{
diff --git a/src/task-manager.c b/src/task-manager.c
index 9734c86..c29e8da 100644
--- a/src/task-manager.c
+++ b/src/task-manager.c
@@ -266,6 +266,7 @@ model_update_tree_iter (GtkTreeModel *model, GtkTreeIter *iter, Task *task)
 
 	g_free (background);
 	g_free (foreground);
+	g_free (old_state);
 }
 
 static void



More information about the Xfce4-commits mailing list