Help with GtkBuilder memory leak
- From: Giovanni Panozzo <giovanni panozzo it>
- To: gtk-app-devel-list gnome org
- Subject: Help with GtkBuilder memory leak
- Date: Thu, 2 Jun 2016 17:03:10 +0200
I'm trying to identify some memory leaks of my application using
-fsanitize=address of GCC.
But really I came to a point where all seems to be inside GTK.
Here is my small test program, compile
----- builderleak.c -------------------------------------
#include <gtk/gtk.h>
GtkApplicationWindow *w;
static void
activate (GtkApplication* app,
gpointer user_data)
{
GtkBuilder* b;
b = gtk_builder_new_from_file("builderleak.glade");
w = GTK_APPLICATION_WINDOW(gtk_builder_get_object(b, "mainwin"));
g_object_set(w, "application", app, NULL);
}
int
main (int argc,
char **argv)
{
GtkApplication *app;
int status;
app = gtk_application_new ("org.gtk.builderleak",
G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
----------------------------------------------
----- builderleak.glade ----------------------
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkApplicationWindow" id="mainwin">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">label</property>
</object>
</child>
</object>
</interface>
--------------------------------------------------
Just compile the above builderleak.c with
gcc `pkg-config --cflags gtk+-3.0` -o builderleak builderleak.c
`pkg-config --libs gtk+-3.0` -fsanitize=address
[tested on current Arch Linux, with gtk3 3.20.6-1]
And execute it.
When closing the main window, the application will exit, but the address
sanitizer will shows you a lot of memory leaks of objects allocated by
libfontconfig.
Here is part of the address sanitizer output:
=================================================================
==14900==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 1280 byte(s) in 2 object(s) allocated from:
#0 0x7f56220d8120 in __interceptor_realloc
/build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:59
#1 0x7f561d86fb9a (/usr/lib/libfontconfig.so.1+0x1db9a)
Indirect leak of 3168 byte(s) in 99 object(s) allocated from:
#0 0x7f56220d7d58 in __interceptor_malloc
/build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:38
#1 0x7f561d85e0ef (/usr/lib/libfontconfig.so.1+0xc0ef)
Indirect leak of 1340 byte(s) in 114 object(s) allocated from:
#0 0x7f56220d7d58 in __interceptor_malloc
/build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:38
#1 0x7f561f854ab9 in __strdup (/usr/lib/libc.so.6+0x7dab9)
...
Just swap the internal GtkLabel widget with a GtkDrawingArea, and all
memory leaks.
The question is: is my program which is causing all these memory leaks ?
Why ?
Thank you
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]