[libvirt] [PATCH] Don't free NULL network in cmdNetworkUpdate

Eric Blake eblake at redhat.com
Tue Aug 27 12:18:51 UTC 2013


On 08/27/2013 06:11 AM, Michal Privoznik wrote:
>> All _internal_ vir*Free functions should be NOPs.  All public vir*Free
>> APIs (including virNetworkFree) are documented to explicitly fail on
>> NULL arguments (more precisely, on any argument not created by an
>> earlier API call), and we cannot change that behavior as it would be an
>> API change that violates back-compat.
> 
> Why it would break backward compatibility? I think it will break forward
> compatibility instead (which we don't care about). That is, currently
> apps have to use:
> 
> virXPtr obj = NULL;
> 
> obj = virLookupBy..();
> 
> ... do something with obj;
> 
> ret = 0;
> cleanup:
> if (obj)
>   virXFree(obj);
> 
> 
> However, if virXFree would accept NULL, it won't affect older
> applications, while new can just:
> 
> cleanup:
> virXFree(obj);
> 
> But then again, this is forward compatibility (the code won't work with
> downgraded libvirtd) - but who cares?

Back-compat says because we documented it, a user can expect:

virXFree(NULL);

to raise an error.  If we change things so that it no longer raises an
error, then their code that was expecting an error may misbehave because
it now goes into code paths that were not previously present.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 621 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20130827/ed5d931a/attachment-0001.sig>


More information about the libvir-list mailing list