This is the mail archive of the guile-gtk@sources.redhat.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GdkEvent copy under signal handler (was: Fixed memory leaks ingdk-1.2.defs)


Marko Rauhamaa <marko@pacujo.net> writes:
>
>  - gdk-1.2.defs: Removed copy options (previously: gdk_..._ref,
>    gtk_no_copy, gtk_fake_copy, gdk_..._copy).

This included GdkEvent I take it.  It's best to give the full name of
each function and/or type, rather than "...", so they can be located
by a grep etc.

I believe this has introduced a bug in the handling of GdkEvent
objects.  An event passed to a signal handler is not copied, and can
end up being freed while still in use.

To observe this, add a fake version of gdk_event_free into guile-gtk.c

	void
	gdk_event_free (GdkEvent *e)
	{
	  printf ("gdk_event_free %p\n", e);
	}

And run a little program

	(use-modules (gtk gtk))
	(define w (gtk-window-new 'toplevel))
	(gtk-widget-add-events w '(pointer-motion-mask))
	(define e #f)
	(gtk-signal-connect w "motion_notify_event"
	                    (lambda (event)
	                      (format #t "prev event ~a\n" e)
	                      (set! e event)))
	(gtk-widget-show-all w)
	(gtk-main)

move the mouse across the window created.  The output is something
like

	gdk_event_free 0x80b1b7c
	prev event #<GdkEvent 80b1b7c>

0x80b1b7c has been freed while it's still in the "e" variable.


I propose to add back the copy option,

        * gdk-1.2.defs (GdkEvent): Reinstate copy option gdk_event_copy, and
        describe why it's there.

I believe all functions which return a GdkEvent (namely gdk_event_get,
gdk_event_peek, gdk_event_get_graphics_expose) have their own
copyingness specified and are therefore unaffected by this change.

Attachment: gdk-1.2.defs.gdk-event-copy.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]