[evolution] Fix few memory leaks in internal test programs
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Fix few memory leaks in internal test programs
- Date: Mon, 5 Aug 2019 16:05:54 +0000 (UTC)
commit 0480743845be5f875ab14800fac6f78a24ff65a2
Author: Milan Crha <mcrha redhat com>
Date: Mon Aug 5 18:00:53 2019 +0200
Fix few memory leaks in internal test programs
Connecting gtk_main_quit() directly to "delete-event" may not destroy
the window, thus make sure the callback returns FALSE, to have the window
properly destroyed.
In the test-source-selector specifically, when the opened client has
an active view, the view holds another reference to the client, thus
unreffing only the client in the hash table doesn't free it, neither
the view, which is assigned on the client instance, thus add a special
destroy callback and unset the view on the client first, then unref
the client.
src/e-util/evolution-source-viewer.c | 12 +++++++++++-
src/e-util/test-category-completion.c | 12 +++++++++++-
src/e-util/test-mail-signatures.c | 12 +++++++++++-
src/e-util/test-preferences-window.c | 18 +++++++++---------
src/e-util/test-source-selector.c | 27 +++++++++++++++++++++++++--
src/e-util/test-tree-view-frame.c | 2 +-
6 files changed, 68 insertions(+), 15 deletions(-)
---
diff --git a/src/e-util/evolution-source-viewer.c b/src/e-util/evolution-source-viewer.c
index 385146edb2..d5a355b344 100644
--- a/src/e-util/evolution-source-viewer.c
+++ b/src/e-util/evolution-source-viewer.c
@@ -1148,6 +1148,16 @@ e_source_viewer_build_display_tree (ESourceViewer *viewer)
return root;
}
+static gboolean
+window_delete_event_cb (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ gtk_main_quit ();
+
+ return FALSE;
+}
+
gint
main (gint argc,
gchar **argv)
@@ -1171,7 +1181,7 @@ main (gint argc,
g_signal_connect (
viewer, "delete-event",
- G_CALLBACK (gtk_main_quit), NULL);
+ G_CALLBACK (window_delete_event_cb), NULL);
gtk_widget_show (viewer);
diff --git a/src/e-util/test-category-completion.c b/src/e-util/test-category-completion.c
index 3b68e4ba59..ef0a0630a1 100644
--- a/src/e-util/test-category-completion.c
+++ b/src/e-util/test-category-completion.c
@@ -16,6 +16,16 @@
#include <e-util/e-util.h>
+static gboolean
+window_delete_event_cb (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ gtk_main_quit ();
+
+ return FALSE;
+}
+
static gboolean
on_idle_create_widget (void)
{
@@ -29,7 +39,7 @@ on_idle_create_widget (void)
g_signal_connect (
window, "delete-event",
- G_CALLBACK (gtk_main_quit), NULL);
+ G_CALLBACK (window_delete_event_cb), NULL);
vgrid = g_object_new (
GTK_TYPE_GRID,
diff --git a/src/e-util/test-mail-signatures.c b/src/e-util/test-mail-signatures.c
index bfbea91ceb..95ad835668 100644
--- a/src/e-util/test-mail-signatures.c
+++ b/src/e-util/test-mail-signatures.c
@@ -87,6 +87,16 @@ signature_combo_changed_cb (EMailSignatureComboBox *combo_box,
g_object_ref (web_view));
}
+static gboolean
+window_delete_event_cb (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ gtk_main_quit ();
+
+ return FALSE;
+}
+
gint
main (gint argc,
gchar **argv)
@@ -118,7 +128,7 @@ main (gint argc,
g_signal_connect (
widget, "delete-event",
- G_CALLBACK (gtk_main_quit), NULL);
+ G_CALLBACK (window_delete_event_cb), NULL);
container = widget;
diff --git a/src/e-util/test-preferences-window.c b/src/e-util/test-preferences-window.c
index 9b4c13c1b0..4b8e552ada 100644
--- a/src/e-util/test-preferences-window.c
+++ b/src/e-util/test-preferences-window.c
@@ -71,14 +71,13 @@ add_pages (EPreferencesWindow *preferences_window)
create_page_two, 2);
}
-static gint
-delete_event_callback (GtkWidget *widget,
- GdkEventAny *event,
- gpointer data)
+static void
+window_notify_visible_cb (GObject *object,
+ GParamSpec *param,
+ gpointer user_data)
{
- gtk_main_quit ();
-
- return TRUE;
+ if (!gtk_widget_get_visible (GTK_WIDGET (object)))
+ gtk_main_quit ();
}
gint
@@ -93,8 +92,8 @@ main (gint argc,
gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);
g_signal_connect (
- window, "delete-event",
- G_CALLBACK (delete_event_callback), NULL);
+ window, "notify::visible",
+ G_CALLBACK (window_notify_visible_cb), NULL);
add_pages (E_PREFERENCES_WINDOW (window));
e_preferences_window_setup (E_PREFERENCES_WINDOW (window));
@@ -103,6 +102,7 @@ main (gint argc,
gtk_main ();
+ gtk_widget_destroy (window);
e_misc_util_free_global_memory ();
return 0;
diff --git a/src/e-util/test-source-selector.c b/src/e-util/test-source-selector.c
index 44231f43e5..3147c9ef46 100644
--- a/src/e-util/test-source-selector.c
+++ b/src/e-util/test-source-selector.c
@@ -64,6 +64,19 @@ selection_changed_callback (ESourceSelector *selector)
dump_selection (selector, extension_name);
}
+static void
+unset_view_and_unref_client (gpointer ptr)
+{
+ EClient *client = ptr;
+
+ g_return_if_fail (E_IS_CLIENT (client));
+
+ /* To have it free the view and unref its own reference to 'client' */
+ g_object_set_data (G_OBJECT (client), VIEW_KEY, NULL);
+
+ g_object_unref (client);
+}
+
static void
enable_widget_if_opened_cb (ESourceSelector *selector,
GtkWidget *widget)
@@ -795,7 +808,7 @@ create_page (ESourceRegistry *registry,
(GHashFunc) g_direct_hash,
(GEqualFunc) g_direct_equal,
(GDestroyNotify) g_object_unref,
- (GDestroyNotify) g_object_unref);
+ (GDestroyNotify) unset_view_and_unref_client);
g_object_set_data_full (
G_OBJECT (selector),
OPENED_KEY,
@@ -821,6 +834,16 @@ create_page (ESourceRegistry *registry,
return GTK_WIDGET (grid);
}
+static gboolean
+window_delete_event_cb (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ gtk_main_quit ();
+
+ return FALSE;
+}
+
static gint
on_idle_create_widget (ESourceRegistry *registry)
{
@@ -831,7 +854,7 @@ on_idle_create_widget (ESourceRegistry *registry)
g_signal_connect (
window, "delete-event",
- G_CALLBACK (gtk_main_quit), NULL);
+ G_CALLBACK (window_delete_event_cb), NULL);
notebook = gtk_notebook_new ();
gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE);
diff --git a/src/e-util/test-tree-view-frame.c b/src/e-util/test-tree-view-frame.c
index b5bfa3ee61..962d247cfe 100644
--- a/src/e-util/test-tree-view-frame.c
+++ b/src/e-util/test-tree-view-frame.c
@@ -13,7 +13,7 @@ delete_event_cb (GtkWidget *widget,
{
gtk_main_quit ();
- return TRUE;
+ return FALSE;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]