public inbox for guile-gtk@sourceware.org
 help / color / mirror / Atom feed
From: Kevin Ryde <user42@zip.com.au>
To: guile-gtk@sources.redhat.com
Subject: Re: gtk-container-children memory leak
Date: Thu, 19 Jun 2003 01:14:00 -0000	[thread overview]
Message-ID: <87r85qeunk.fsf@zip.com.au> (raw)
In-Reply-To: <87wukuio68.fsf@zip.com.au>

[-- Attachment #1: Type: text/plain, Size: 685 bytes --]

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.


[-- Attachment #2: gtk-support.c.container-children.diff --]
[-- Type: text/plain, Size: 1029 bytes --]

--- 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;
+}
+
+
+
 \f
 
 /* These SCM_PROCs are here to have them initialized in

[-- Attachment #3: guile-gtk.h.container-children.diff --]
[-- Type: text/plain, Size: 363 bytes --]

--- 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,

[-- Attachment #4: gtk-1.2.defs.container-children.diff --]
[-- Type: text/plain, Size: 398 bytes --]

--- 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

      reply	other threads:[~2003-06-19  1:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-24 15:05 Kevin Ryde
2003-06-19  1:14 ` Kevin Ryde [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r85qeunk.fsf@zip.com.au \
    --to=user42@zip.com.au \
    --cc=guile-gtk@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).