[libvirt] [PATCH 5/5] don't check for NULL before calling virHashFree

Eric Blake eblake at redhat.com
Fri Feb 18 20:22:41 UTC 2011


On 02/18/2011 12:30 PM, Jim Meyering wrote:
>>> -    if (doms->objs)
>>> -        virHashFree(doms->objs, virDomainObjListDeallocator);
>>> +    virHashFree(doms->objs, virDomainObjListDeallocator);
>>
>> I tried adding --name=virHashFree to the useless_free_options variable
>> in cfg.mk, to see if that would prevent regressions.  However, it
>> appears that this two-argument free-like function is not picked up by
>> the heuristics in the useless-if-before-free script (it only works on
>> one-argument functions).

> Right.  useless-if-before-free deliberately detects only
> one-argument free-like functions.

An even better idea - as long as we're improving hash.h, why not fix
things to pass the destructor in the Create call, rather than the Free
call.  Then freeing is a one-argument operation, using the destructor
callback registered inside the virHash object, rather than a
two-argument operation requiring the caller to pass in the destructor.
At which point, we've defined away the problem of useless-if-before-free.

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

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


More information about the libvir-list mailing list