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.
--
Stephen Gallagher
RHCE 804006346421761
Delivering value year after year.
Red Hat ranks #1 in value among software vendors.
http://www.redhat.com/promo/vendor/