From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27510 invoked by alias); 19 Jun 2003 01:14:09 -0000 Mailing-List: contact guile-gtk-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: guile-gtk-owner@sources.redhat.com Received: (qmail 27470 invoked from network); 19 Jun 2003 01:14:08 -0000 Received: from unknown (HELO snoopy.pacific.net.au) (61.8.0.36) by sources.redhat.com with SMTP; 19 Jun 2003 01:14:08 -0000 Received: from sunny.pacific.net.au (sunny.pacific.net.au [203.2.228.40]) by snoopy.pacific.net.au (8.12.3/8.12.3/Debian-6.3) with ESMTP id h5J1E6Yd015088 for ; Thu, 19 Jun 2003 11:14:07 +1000 Received: from wisma.pacific.net.au (wisma.pacific.net.au [210.23.129.72]) by sunny.pacific.net.au with ESMTP id h5J1E6Qg013620 for ; Thu, 19 Jun 2003 11:14:06 +1000 (EST) Received: from localhost (ppp13.dyn228.pacific.net.au [203.143.228.13]) by wisma.pacific.net.au (8.12.9/8.12.9) with ESMTP id h5J1E3nh023833 for ; Thu, 19 Jun 2003 11:14:04 +1000 (EST) Received: from gg by localhost with local (Exim 3.35 #1 (Debian)) id 19Snzs-0004C1-00; Thu, 19 Jun 2003 11:13:52 +1000 To: guile-gtk@sources.redhat.com Subject: Re: gtk-container-children memory leak References: <87wukuio68.fsf@zip.com.au> From: Kevin Ryde Mail-Copies-To: never Date: Thu, 19 Jun 2003 01:14:00 -0000 Message-ID: <87r85qeunk.fsf@zip.com.au> User-Agent: Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.2 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-SW-Source: 2003-q2/txt/msg00146.txt.bz2 --=-=-= Content-length: 685 I wrote: > > I think gtk-container-children might be leaking memory. I propose to free the returned list with the following change. * gtk-support.c (_sgtk_helper_toscm_copy_GtkWidget): New function. * gtk-support.c, guile-gtk.h (gtk_container_children_interp): New function. * gdk-1.2.defs (gtk_container_children): Use it. This change fixes a memory leak in gtk-container-children, the GList returned by gtk_container_children must be freed by the caller. I suppose I could use _sgtk_helper_toscm_copy_GtkWidget from the glue file if it wasn't static. The name would be ok to be a global. Easy enough to duplicate for now though. --=-=-= Content-Disposition: attachment; filename=gtk-support.c.container-children.diff Content-length: 1029 --- gtk-support.c.~1.6.~ 2003-05-08 08:03:54.000000000 +1000 +++ gtk-support.c 2003-06-15 16:10:38.000000000 +1000 @@ -160,6 +160,30 @@ gtk_selection_data_data (GtkSelectionData* data) { return (data->length >= 0) ? scm_mem2string (data->data, data->length) : SCM_BOOL_F; } + +/* Same as in gtk-glue.c, could share with that file if it exported this. */ +static SCM +_sgtk_helper_toscm_copy_GtkWidget (void *mem) +{ + return sgtk_wrap_gtkobj ((GtkObject*)(*(GtkWidget**)mem)); +} + +/* The list returned by gtk_container_children must be freed by the caller. + Could do this sort of thing with a .defs file option, but easy enough to + have explicit code while there's only a few such. */ +SCM +gtk_container_children_interp (GtkContainer *container) +{ + GList* children; + SCM ret; + children = gtk_container_children (container); + ret = sgtk_list2scm (children, _sgtk_helper_toscm_copy_GtkWidget); + g_list_free (children); + return ret; +} + + + /* These SCM_PROCs are here to have them initialized in --=-=-= Content-Disposition: attachment; filename=guile-gtk.h.container-children.diff Content-length: 363 --- guile-gtk.h.~1.25.~ 2003-06-15 09:08:11.000000000 +1000 +++ guile-gtk.h 2003-06-15 16:11:10.000000000 +1000 @@ -322,6 +322,7 @@ typedef int GtkWidgetFlags; #endif +SCM gtk_container_children_interp (GtkContainer *container); gchar *gtk_label_get_interp (GtkLabel *label); void gtk_menu_popup_interp (GtkMenu *menu, GtkWidget *parent_menu_shell, --=-=-= Content-Disposition: attachment; filename=gtk-1.2.defs.container-children.diff Content-length: 398 --- gtk-1.2.defs.~1.10.~ 2003-04-04 08:07:41.000000000 +1000 +++ gtk-1.2.defs 2003-06-15 16:08:51.000000000 +1000 @@ -888,8 +888,8 @@ (scm-name "gtk-container-foreach-full") (protection #t)) -(define-func gtk_container_children - ((list GtkWidget)) +(define-func gtk_container_children_interp + SCM ;; list of GtkWidget ((GtkContainer container))) (define-func gtk_container_focus --=-=-=--