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

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

 



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@xxxxxxxxxx>
> ---

>
> +
> +# 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.

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]