[gtksourceview] Completion: avoid memory leaks
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] Completion: avoid memory leaks
- Date: Mon, 11 Mar 2013 19:56:44 +0000 (UTC)
commit 8a760e4cf4c63ca1393c213e6700c4bade08624e
Author: Sébastien Wilmet <swilmet gnome org>
Date: Mon Mar 11 00:12:03 2013 +0100
Completion: avoid memory leaks
gtksourceview/gtksourcecompletion.c | 14 ++++++++++
tests/test-completion.c | 50 +++++++++++++++++++++++++---------
2 files changed, 51 insertions(+), 13 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 339b76f..34f2572 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -1354,6 +1354,19 @@ gtk_source_completion_dispose (GObject *object)
g_clear_object (&completion->priv->view);
g_clear_object (&completion->priv->default_info);
+ g_clear_object (&completion->priv->model_proposals);
+
+ if (completion->priv->info_window != NULL)
+ {
+ gtk_widget_destroy (GTK_WIDGET (completion->priv->info_window));
+ completion->priv->info_window = NULL;
+ }
+
+ if (completion->priv->main_window != NULL)
+ {
+ gtk_widget_destroy (GTK_WIDGET (completion->priv->main_window));
+ completion->priv->main_window = NULL;
+ }
g_list_free (completion->priv->interactive_providers);
completion->priv->interactive_providers = NULL;
@@ -2126,6 +2139,7 @@ static void
init_info_window (GtkSourceCompletion *completion)
{
completion->priv->info_window = gtk_source_completion_info_new ();
+ g_object_ref_sink (completion->priv->info_window);
gtk_window_set_attached_to (GTK_WINDOW (completion->priv->info_window),
GTK_WIDGET (completion->priv->main_window));
diff --git a/tests/test-completion.c b/tests/test-completion.c
index c022e09..f357109 100644
--- a/tests/test-completion.c
+++ b/tests/test-completion.c
@@ -3,6 +3,7 @@
* This file is part of GtkSourceView
*
* Copyright (C) 2007 - Jesús Barbero Rodríguez <chuchiperriman gmail com>
+ * Copyright (C) 2013 - Sébastien Wilmet <swilmet gnome org>
*
* GtkSourceView is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -145,8 +146,36 @@ test_provider_iface_init (GtkSourceCompletionProviderIface *iface)
}
static void
+test_provider_dispose (GObject *gobject)
+{
+ TestProvider *self = (TestProvider *)gobject;
+
+ g_list_free_full (self->proposals, g_object_unref);
+ self->proposals = NULL;
+
+ g_clear_object (&self->icon);
+
+ G_OBJECT_CLASS (test_provider_parent_class)->dispose (gobject);
+}
+
+static void
+test_provider_finalize (GObject *gobject)
+{
+ TestProvider *self = (TestProvider *)gobject;
+
+ g_free (self->name);
+ self->name = NULL;
+
+ G_OBJECT_CLASS (test_provider_parent_class)->finalize (gobject);
+}
+
+static void
test_provider_class_init (TestProviderClass *klass)
{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->dispose = test_provider_dispose;
+ gobject_class->finalize = test_provider_finalize;
}
static void
@@ -210,13 +239,6 @@ test_provider_set_random (TestProvider *provider)
}
static void
-destroy_cb (GtkWidget *object,
- gpointer user_data)
-{
- gtk_main_quit ();
-}
-
-static void
remember_toggled_cb (GtkToggleButton *button,
gpointer user_data)
{
@@ -263,8 +285,7 @@ show_icons_toggled_cb (GtkToggleButton *button,
NULL);
}
-
-static GtkWidget*
+static GtkWidget *
create_window (void)
{
GtkWidget *window;
@@ -309,7 +330,7 @@ create_window (void)
gtk_container_add (GTK_CONTAINER (window), vbox);
g_signal_connect (window, "destroy",
- G_CALLBACK (destroy_cb),
+ G_CALLBACK (gtk_main_quit),
NULL);
g_signal_connect (remember, "toggled",
G_CALLBACK (remember_toggled_cb),
@@ -328,7 +349,7 @@ create_window (void)
}
static void
-create_completion(void)
+create_completion (void)
{
GtkSourceCompletionWords *prov_words;
@@ -345,26 +366,29 @@ create_completion(void)
NULL);
g_object_set (prov_words, "priority", 10, NULL);
+ g_object_unref (prov_words);
/* Fixed provider: the proposals don't change */
TestProvider *tp = g_object_new (test_provider_get_type (), NULL);
test_provider_set_fixed (tp);
tp->priority = 5;
- tp->name = "Fixed Provider";
+ tp->name = g_strdup ("Fixed Provider");
gtk_source_completion_add_provider (comp,
GTK_SOURCE_COMPLETION_PROVIDER (tp),
NULL);
+ g_object_unref (tp);
/* Random provider: the proposals vary on each populate */
tp = g_object_new (test_provider_get_type (), NULL);
test_provider_set_random (tp);
tp->priority = 1;
- tp->name = "Random Provider";
+ tp->name = g_strdup ("Random Provider");
gtk_source_completion_add_provider (comp,
GTK_SOURCE_COMPLETION_PROVIDER (tp),
NULL);
+ g_object_unref (tp);
}
int
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]