Re: gtk_label_set_text leaking?



On Wed, Dec 27, 2006 at 10:05:07PM -0800, David L wrote:
> I noticed one of my gtk applications seems to be
> leaking memory on my fc6 box that I updated recently.
> I think I've tracked it down to a leak in gtk_label_set_text.
> The following simple example leaks on one of my computers
> (an fc6 box with "yum update" run today... uses gtk2-2.10.4-8.fc6).
> Am I doing something wrong or is there a gtk bug?
>
> while (1) {
>   gtk_main_iteration();
>   gtk_label_set_text((GtkLabel *)mylabel, "f");
> }
> }

Since I don't trust this to catch up with event processing
I rewrote it to a less suspicious form with g_idle_add()
(attached at the end).

It does leak memory with gtk2-2.10.4-10.fc6, but it does
*not* leak memory (not those large quantities anyway) with
gtk+-2.10.6 I have compiled from source.  The obvious leak
in the fc6 version is (after 5k iterations):

  79,936 bytes in 4,996 blocks are definitely lost in loss record 1,890 of 1,892
     at 0x4A05879: malloc (vg_replace_malloc.c:149)
     by 0x3267E33D9A: g_malloc (gmem.c:131)
     by 0x3267E45E76: g_memdup (gstrfuncs.c:108)
     by 0x3268609343: boxed_proxy_lcopy_value (gboxed.c:333)
     by 0x30BA42E224: gtk_widget_style_get_valist (gtkwidget.c:7590)
     by 0x30BA42E3AB: gtk_widget_style_get (gtkwidget.c:7624)
     by 0x30BA42E44E: gtk_widget_get_draw_rectangle (gtkwidget.c:2677)
     by 0x30BA430D10: gtk_widget_region_intersect (gtkwidget.c:4172)
     by 0x30BA2A702E: gtk_container_propagate_expose (gtkcontainer.c:2457)
     by 0x30BA271F3F: gtk_box_forall (gtkbox.c:670)
     by 0x30BA2A7ACD: gtk_container_expose (gtkcontainer.c:2372)
     by 0x30BA33017C: _gtk_marshal_BOOLEAN__BOXED (gtkmarshalers.c:84)

  79,968 bytes in 4,998 blocks are definitely lost in loss record 1,891 of 1,892
     at 0x4A05879: malloc (vg_replace_malloc.c:149)
     by 0x3267E33D9A: g_malloc (gmem.c:131)
     by 0x3267E45E76: g_memdup (gstrfuncs.c:108)
     by 0x3268609343: boxed_proxy_lcopy_value (gboxed.c:333)
     by 0x30BA42E224: gtk_widget_style_get_valist (gtkwidget.c:7590)
     by 0x30BA42E3AB: gtk_widget_style_get (gtkwidget.c:7624)
     by 0x30BA42E44E: gtk_widget_get_draw_rectangle (gtkwidget.c:2677)
     by 0x30BA42E4ED: gtk_widget_queue_shallow_draw (gtkwidget.c:2960)
     by 0x30BA4324F7: gtk_widget_queue_resize (gtkwidget.c:2789)
     by 0x30BA319DA1: gtk_label_recalculate (gtklabel.c:1171)
     by 0x30BA31A8E6: gtk_label_set_text (gtklabel.c:1196)
     by 0x400B61: set_label (labelleak.c:8)

  80,016 bytes in 5,001 blocks are definitely lost in loss record 1,892 of 1,892
     at 0x4A05879: malloc (vg_replace_malloc.c:149)
     by 0x3267E33D9A: g_malloc (gmem.c:131)
     by 0x3267E45E76: g_memdup (gstrfuncs.c:108)
     by 0x3268609343: boxed_proxy_lcopy_value (gboxed.c:333)
     by 0x30BA42E224: gtk_widget_style_get_valist (gtkwidget.c:7590)
     by 0x30BA42E3AB: gtk_widget_style_get (gtkwidget.c:7624)
     by 0x30BA42E44E: gtk_widget_get_draw_rectangle (gtkwidget.c:2677)
     by 0x30BA42E59B: widget_add_child_draw_rectangle (gtkwidget.c:2663)
     by 0x30BA271F3F: gtk_box_forall (gtkbox.c:670)
     by 0x30BA42E4AC: gtk_widget_get_draw_rectangle (gtkwidget.c:2689)
     by 0x30BA430D10: gtk_widget_region_intersect (gtkwidget.c:4172)
     by 0x30BA2A702E: gtk_container_propagate_expose (gtkcontainer.c:2457)

Either this is redhat-specific or it has been fixed upstream
meanwhile.  In both cases it makes sense to report it to
redhat, not to Gtk+.

Yeti


--
http://physics.muni.cz/~yeti/pf2007.png


============================================================================
#include <gtk/gtk.h>

static gboolean
set_label(GtkLabel *label)
{
    gtk_label_set_text(label, "f");
    return TRUE;
}

int
main(int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *vbox;
    GtkWidget *mylabel;

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
    vbox = gtk_vbox_new(FALSE, 0);
    gtk_container_add (GTK_CONTAINER(window), vbox);
    mylabel = gtk_label_new("a");
    gtk_box_pack_start(GTK_BOX(vbox), mylabel, FALSE, FALSE, 0);
    gtk_widget_show_all(window);
    g_idle_add((GSourceFunc)set_label, GTK_LABEL(mylabel));
    gtk_main();

    return 0;
}




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]