Re: g_main_dispatch frees objects for input_callback before using them (how to prevent it?)

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

 



On Fri, 10 Oct 2014 03:11:41 +0200
Thomas DEBESSE <dev@xxxxxxxxxxxxx> wrote:
> Hi everyone, I'm trying to revive a very old project: XQF, a
> graphical game server browser.
> 
> Many things are deprecated in this old code, but there is one that
> particularly bothers me: I try to port gdk_input_* calls to g_io.
> 
> I do something like that:
> https://github.com/XQF/xqf/commit/cf2b506547755c6f7176979cf8b7db189c14c7e4
> 
> I rewrite some callbacks with new functions, new types,
> gdk_input_remove is replaced by g_source_remove, gdk_input_add is
> replaced by g_io_add_watch and I use GioChannel, etc.
> 
> So everything seems to work… until g_main_dispatch calls my callback.
> 
> You can read all my investigations here:
> https://github.com/XQF/xqf/issues/4
> 
> I see g_io_add_watch add a callback on a channel with a user_data
> reference, and yes, It works when I trace the code with gdb. The
> callback is added with the pointer to user_data, and when I trace the
> execution, pointers are the good ones.
> 
> But when g_io_add_watch returns to the main loop, g_main_dispatch
> frees some objects and then call the callback… and segfaults because
> the callback was launched with a null pointer user_data!
> 
> You can read a complete walktrough here :
> https://github.com/XQF/xqf/issues/4#issuecomment-58442986
> 
> I'm looking for a way to prevent g_main_dispatch to forget the
> user_data and conditions before the call of my input_callback.
> 
> Is anyone have any idea what's going on?

No, but this change can't be right:

  -
  -static void stat_master_input_callback (struct stat_conn *conn, int fd,
  -                                        GdkInputCondition condition) {
  +static GIOFunc stat_master_input_callback (struct stat_conn *conn, int fd,
  +                                           GIOCondition condition) {

because you do not appear actually to change the return statement in the
function stat_master_input_callback(), which was void before (unless this
is in a different commit).  Is this now a callback factory function - it
didn't appear to be so before.

This may not be an issue in your code but note that a callback function
used as an io watch must return gboolean, and the return value is used to
determine whether the io watch is removed from the list of sources.
If you cast a function returning void to GIOFunc, you will get random
and undefined results.

Chris
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list





[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux