[goffice] Debug: GO_DEBUG=leaks will now report leaks for ui files and more.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Debug: GO_DEBUG=leaks will now report leaks for ui files and more.
- Date: Sat, 10 Jan 2015 01:12:58 +0000 (UTC)
commit 3045a2b36b77b8005ad018c9a3fdb2b09dc0f980
Author: Morten Welinder <terra gnome org>
Date: Fri Jan 9 20:11:46 2015 -0500
Debug: GO_DEBUG=leaks will now report leaks for ui files and more.
goffice/gtk/goffice-gtk.c | 28 +++++++++++++++++++++++-----
goffice/utils/go-glib-extras.c | 34 ++++++++++++++++++++++++++++++++++
goffice/utils/go-glib-extras.h | 3 +++
3 files changed, 60 insertions(+), 5 deletions(-)
---
diff --git a/goffice/gtk/goffice-gtk.c b/goffice/gtk/goffice-gtk.c
index b9bc4e4..8ed1085 100644
--- a/goffice/gtk/goffice-gtk.c
+++ b/goffice/gtk/goffice-gtk.c
@@ -178,7 +178,7 @@ apply_ui_from_file (GtkBuilder *gui, GsfInput *src, const char *uifile,
**/
GtkBuilder *
go_gtk_builder_load (char const *uifile,
- char const *domain, GOCmdContext *gcc)
+ char const *domain, GOCmdContext *gcc)
{
GtkBuilder *gui;
GError *error = NULL;
@@ -224,6 +224,18 @@ go_gtk_builder_load (char const *uifile,
} else if (error)
g_error_free (error);
+ if (gui && go_debug_flag ("leaks")) {
+ GSList *l, *objs = gtk_builder_get_objects (gui);
+ for (l = objs; l; l = l->next) {
+ GObject *obj = l->data;
+ /* Darn -- cannot access object name! */
+ char *name = g_strdup_printf ("Anonymous from %s", uifile);
+ go_debug_check_finalized (obj, name);
+ g_free (name);
+ }
+ g_slist_free (objs);
+ }
+
return gui;
}
@@ -1590,11 +1602,12 @@ go_gtk_widget_render_icon_pixbuf (GtkWidget *widget,
GdkScreen *screen;
GtkIconTheme *theme;
int pixels;
+ GdkPixbuf *res;
/* The widget really ought to be mapped. */
- screen = gtk_widget_get_screen (widget);
- if (!screen)
- screen = gdk_screen_get_default ();
+ screen = gtk_widget_has_screen (widget)
+ ? gtk_widget_get_screen (widget)
+ : gdk_screen_get_default ();
theme = gtk_icon_theme_get_for_screen (screen);
switch (size) {
@@ -1613,5 +1626,10 @@ go_gtk_widget_render_icon_pixbuf (GtkWidget *widget,
break;
}
- return gtk_icon_theme_load_icon (theme, icon_name, pixels, 0, NULL);
+ res = gtk_icon_theme_load_icon (theme, icon_name, pixels, 0, NULL);
+
+ if (res && go_debug_flag ("leaks"))
+ go_debug_check_finalized (res, icon_name);
+
+ return res;
}
diff --git a/goffice/utils/go-glib-extras.c b/goffice/utils/go-glib-extras.c
index 0d23da6..f556436 100644
--- a/goffice/utils/go-glib-extras.c
+++ b/goffice/utils/go-glib-extras.c
@@ -1168,9 +1168,43 @@ go_debug_flag (const char *flag)
return g_parse_debug_string (g_getenv ("GO_DEBUG"), &key, 1) != 0;
}
+static GHashTable *finalize_hash;
+
+static void
+cb_finalized (gpointer data, GObject *victim)
+{
+ g_hash_table_remove (finalize_hash, victim);
+}
+
+void
+go_debug_check_finalized (gpointer obj, const char *id)
+{
+ g_return_if_fail (G_IS_OBJECT (obj));
+
+ if (!finalize_hash)
+ finalize_hash = g_hash_table_new_full
+ (g_direct_hash, g_direct_equal,
+ NULL, (GDestroyNotify)g_free);
+ g_hash_table_replace (finalize_hash, obj, g_strdup (id));
+ g_object_weak_ref (obj, cb_finalized, NULL);
+}
+
+
void
_go_glib_extras_shutdown (void)
{
g_free (go_real_name);
go_real_name = NULL;
+ if (finalize_hash) {
+ GHashTableIter hiter;
+ gpointer key, value;
+ g_hash_table_iter_init (&hiter, finalize_hash);
+ while (g_hash_table_iter_next (&hiter, &key, &value)) {
+ const char *name = value;
+ g_printerr ("%s \"%s\" at %p not finalized.\n",
+ G_OBJECT_TYPE_NAME (key), name, key);
+ }
+ g_hash_table_destroy (finalize_hash);
+ finalize_hash = NULL;
+ }
}
diff --git a/goffice/utils/go-glib-extras.h b/goffice/utils/go-glib-extras.h
index 3a34b5a..99f9edf 100644
--- a/goffice/utils/go-glib-extras.h
+++ b/goffice/utils/go-glib-extras.h
@@ -117,6 +117,9 @@ gboolean go_parse_key_value (const char *options,
gboolean go_debug_flag (const char *flag);
void _go_glib_extras_shutdown (void);
+void go_debug_check_finalized (gpointer obj, const char *id);
+
+
G_END_DECLS
#endif /* GO_GLIB_EXTRAS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]