[libvirt] [PATCH 1/2] virObjectUnref: Set pointer to NULL on dispose

Laine Stump laine at laine.org
Thu Nov 7 11:47:14 UTC 2013


On 11/07/2013 12:39 PM, Michal Privoznik wrote:
> Similarly to VIR_FREE() we can set the pointer passed to virObjectUnref
> to NULL in case of disposing the object. However, to avoid overwriting
> nearly thousands line of code, the virObjectUnref is turned into a macro
> which passes the address of pointer and calls virObjectUnrefInternal
> (the modified version of original virObjectUnref).
>
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---

>
> +
> +# define virObjectUnref(ptr) \
> +        virObjectUnrefInternal((void *) (1 ? (const void *) &(ptr) : (ptr)))

This could help catch some bugs caused by using stale pointers, that
part is good.

I normally don't expect a C function call to have side effects on
something that is passed by value rather than reference. Not the case
for macros, where everything is fair game. But in libvirt we generally
follow the convention of defining macros in ALL_CAPS() to provide a
simple visual cue that there may be side effects.

I do recognize though that updating every use of every vir*Free in the
tree would be a huge diff and cause lots of merge conflicts later when
anyone tried to backport anything. So as usual I'm on the fence about this.




More information about the libvir-list mailing list