pspp-dev
[Top][All Lists]
Advanced

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

Re: Reentrancy in dispose


From: Ben Pfaff
Subject: Re: Reentrancy in dispose
Date: Mon, 16 Jul 2012 08:59:29 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

John Darrington <address@hidden> writes:

> I'm not convinced that some of the dispose routines that we have are
> very reliable at catching reentrancy.
>
> if (thing->obj != NULL)
>   g_object_unref (thing->obj);
> thing->obj = NULL;
>
> The problem is that g_object_unref can cause its argument's dispose 
> routine to run.  Which in turn, could unref a reference it holds on 
> us, and hence run our dispose routine.  Since we haven't yet set thing->obj
> to NULL, it will call g_object_unref on it again.
>
> Have I analysed this correctly?

Yes, I think so.  If that's a possibility (I think that it really
is not in many cases) We either have to do something like this:

    tmp = thing->obj;
    thing->obj = NULL;
    if (tmp)
      g_object_unref (tmp);

or use a "dispose_has_run" variable.  The latter makes me nervous
because it's possible that some (arguably buggy) dispose routine
calls back into us and causes us to allocate something new.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]