On 04/16/2010 03:00 PM, Stephen Gallagher wrote:
On 04/16/2010 02:02 AM, Eugene Indenbom wrote:
> The current implementation of talloc_zfree macro has a substantial
> deficiency: it deallocates memory first and then clears a pointer.
>
> Clearing pointer after deallocation completes could lead to bad side
> effects when callbacks are called during object destruction: the
> callback called from destructor could dereference half-destroyed object
> referenced by the yet-not-cleared pointer.
>
> The above could lead to disastrous effects including memory double free.
>
> The patch attached fixes the issues by using correct free sequence:
> clear pointer first, then deallocate memory block.
>
> Eugene
>
>
My only comment with this patch is that I don't understand why you use
(ptr) instead of just ptr.
Otherwise, this patch seems intuitively correct, and I like it.
That is some kind of macro writing paranoia: always to surround macro
parameters with parentheses. It should be OK without them, but...
Eugene