valgrind memcheck shows gtk-hello leak memories.



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

hello, all:
        
        I test a very simple gtk program from the gtk-2.0
tutor(http://www.gtk.org/tutorial/x364.html) using valgrind, and it
reports the program leak memories. Is it a gtk's problem(really have
some memory leaks) or a valgrind's BUG?

==2395== LEAK SUMMARY:
==2395==    definitely lost: 36 bytes in 1 blocks.
==2395==    possibly lost:   800 bytes in 20 blocks.
==2395==    still reachable: 543445 bytes in 7071 blocks.
==2395==         suppressed: 0 bytes in 0 blocks.

        The attachments contains the source code & valgrind output result.
        BTW: my gtk+-2.0 version is 2.6.4 and glib-2.0 version is 2.6.3.
valgrind version is 2.2.0

        regards.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)

iD8DBQFDgp6Azm46SfqoYmQRAqUfAJ0endAIzPpfrRVIktdCyYz7f8JjKgCfTSFd
gbAUBk1Hg7xQuzjbiIGbaKw=
=nvV+
-----END PGP SIGNATURE-----
==2395== Memcheck, a memory error detector for x86-linux.
==2395== Copyright (C) 2002-2004, and GNU GPL'd, by Julian Seward et al.
==2395== Using valgrind-2.2.0, a program supervision framework for x86-linux.
==2395== Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward et al.
==2395== For more details, rerun with: -v
==2395== 
==2395== Syscall param write(buf) contains uninitialised or unaddressable byte(s)
==2395==    at 0x1BE78708: write (in /usr/lib/debug/libc-2.3.2.so)
==2395==    by 0x1BF31CF4: _X11TransWrite (in /usr/X11R6/lib/libX11.so.6.2)
==2395==    by 0x1BF124B4: (within /usr/X11R6/lib/libX11.so.6.2)
==2395==    by 0x1BF139D3: _XReply (in /usr/X11R6/lib/libX11.so.6.2)
==2395==  Address 0x1C125B38 is 128 bytes inside a block of size 16384 alloc'd
==2395==    at 0x1B905901: calloc (vg_replace_malloc.c:176)
==2395==    by 0x1BF04D84: XOpenDisplay (in /usr/X11R6/lib/libX11.so.6.2)
==2395==    by 0x1BC0DBE5: gdk_display_open (in /usr/lib/libgdk-x11-2.0.so.0.600.4)
==2395==    by 0x1BBF0E79: gdk_display_open_default_libgtk_only (in /usr/lib/libgdk-x11-2.0.so.0.600.4)
==2395== 
==2395== Syscall param write(buf) contains uninitialised or unaddressable byte(s)
==2395==    at 0x1BE78708: write (in /usr/lib/debug/libc-2.3.2.so)
==2395==    by 0x1BF31CF4: _X11TransWrite (in /usr/X11R6/lib/libX11.so.6.2)
==2395==    by 0x1BF124B4: (within /usr/X11R6/lib/libX11.so.6.2)
==2395==    by 0x1BF12369: _XFlush (in /usr/X11R6/lib/libX11.so.6.2)
==2395==  Address 0x1C125E54 is 924 bytes inside a block of size 16384 alloc'd
==2395==    at 0x1B905901: calloc (vg_replace_malloc.c:176)
==2395==    by 0x1BF04D84: XOpenDisplay (in /usr/X11R6/lib/libX11.so.6.2)
==2395==    by 0x1BC0DBE5: gdk_display_open (in /usr/lib/libgdk-x11-2.0.so.0.600.4)
==2395==    by 0x1BBF0E79: gdk_display_open_default_libgtk_only (in /usr/lib/libgdk-x11-2.0.so.0.600.4)
==2395== 
==2395== ERROR SUMMARY: 5 errors from 2 contexts (suppressed: 81 from 1)
==2395== malloc/free: in use at exit: 544281 bytes in 7092 blocks.
==2395== malloc/free: 47442 allocs, 40350 frees, 6143759 bytes allocated.
==2395== For counts of detected errors, rerun with: -v
==2395== searching for pointers to 7092 not-freed blocks.
==2395== checked 8882488 bytes.
==2395== 
==2395== 
==2395== 36 bytes in 1 blocks are definitely lost in loss record 36 of 129
==2395==    at 0x1B904EDD: malloc (vg_replace_malloc.c:131)
==2395==    by 0x1BE9498B: nss_parse_service_list (nsswitch.c:529)
==2395==    by 0x1BE94261: __GI___nss_database_lookup (nsswitch.c:133)
==2395==    by 0x1C1E42B1: ???
==2395== 
==2395== 
==2395== 800 bytes in 20 blocks are possibly lost in loss record 94 of 129
==2395==    at 0x1B905901: calloc (vg_replace_malloc.c:176)
==2395==    by 0x1BD5EB45: g_malloc0 (in /usr/lib/libglib-2.0.so.0.600.3)
==2395==    by 0x1BD15491: (within /usr/lib/libgobject-2.0.so.0.600.3)
==2395==    by 0x1BD15789: (within /usr/lib/libgobject-2.0.so.0.600.3)
==2395== 
==2395== LEAK SUMMARY:
==2395==    definitely lost: 36 bytes in 1 blocks.
==2395==    possibly lost:   800 bytes in 20 blocks.
==2395==    still reachable: 543445 bytes in 7071 blocks.
==2395==         suppressed: 0 bytes in 0 blocks.
==2395== Reachable blocks (those to which a pointer was found) are not shown.
==2395== To see them, rerun with: --show-reachable=yes
#include <gtk/gtk.h>

/* Our new improved callback.  The data passed to this function
 *  * is printed to stdout. */
static void callback( GtkWidget *widget,
                gpointer   data )
{
        g_print ("Hello again - %s was pressed\n", (gchar *) data);
}

/* another callback */
static gboolean delete_event( GtkWidget *widget,
                GdkEvent  *event,
                gpointer   data )
{
        gtk_main_quit ();
        return FALSE;
}

int main( int   argc,
                char *argv[] )
{
        /* GtkWidget is the storage type for widgets */
        GtkWidget *window;
        GtkWidget *button;
        GtkWidget *box1;

        /* This is called in all GTK applications. Arguments are parsed
         *      * from the command line and are returned to the application. */
        gtk_init (&argc, &argv);

        /* Create a new window */
        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

        /* This is a new call, which just sets the title of our
         *      * new window to "Hello Buttons!" */
        gtk_window_set_title (GTK_WINDOW (window), "Hello Buttons!");

        /* Here we just set a handler for delete_event that immediately
         *      * exits GTK. */
        g_signal_connect (G_OBJECT (window), "delete_event",
                        G_CALLBACK (delete_event), NULL);

        /* Sets the border width of the window. */
        gtk_container_set_border_width (GTK_CONTAINER (window), 10);

        /* We create a box to pack widgets into.  This is described in detail
         *      * in the "packing" section. The box is not really visible, it
         *           * is just used as a tool to arrange widgets. */
        box1 = gtk_hbox_new (FALSE, 0);

        /* Put the box into the main window. */
        gtk_container_add (GTK_CONTAINER (window), box1);

        /* Creates a new button with the label "Button 1". */
        button = gtk_button_new_with_label ("Button 1");

        /* Now when the button is clicked, we call the "callback" function
         *      * with a pointer to "button 1" as its argument */
        g_signal_connect (G_OBJECT (button), "clicked",
                        G_CALLBACK (callback), (gpointer) "button 1");

        /* Instead of gtk_container_add, we pack this button into the invisible
         *      * box, which has been packed into the window. */
        gtk_box_pack_start (GTK_BOX(box1), button, TRUE, TRUE, 0);

        /* Always remember this step, this tells GTK that our preparation for
         *      * this button is complete, and it can now be displayed. */
        gtk_widget_show (button);

        /* Do these same steps again to create a second button */
        button = gtk_button_new_with_label ("Button 2");

        /* Call the same callback function with a different argument,
         *      * passing a pointer to "button 2" instead. */
        g_signal_connect (G_OBJECT (button), "clicked",
                        G_CALLBACK (callback), (gpointer) "button 2");

        gtk_box_pack_start(GTK_BOX (box1), button, TRUE, TRUE, 0);

        /* The order in which we show the buttons is not really important, but I
         *      * recommend showing the window last, so it all pops up at once. */
        gtk_widget_show (button);

        gtk_widget_show (box1);

        gtk_widget_show (window);

        /* Rest in gtk_main and wait for the fun to begin! */
        gtk_main ();

        return 0;
}


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