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

Eric Blake eblake at redhat.com
Fri Feb 18 00:09:41 UTC 2011


[adding Jim to cc, as author of useless-if-before-free]

On 02/17/2011 02:14 PM, Christophe Fergeau wrote:
> virHashFree follows the convention described in HACKING that
> XXXFree() functions can be called with a NULL argument.
> ---
>  src/conf/domain_conf.c  |    6 +---
>  src/datatypes.c         |   51 +++++++++++++++-------------------------------
>  src/qemu/qemu_process.c |    4 +--
>  3 files changed, 20 insertions(+), 41 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 351daf7..e7c3409 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -410,8 +410,7 @@ static void virDomainObjListDeallocator(void *payload, const char *name ATTRIBUT
>  
>  void virDomainObjListDeinit(virDomainObjListPtr doms)
>  {
> -    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).

ACK to your patch as-is, so I pushed it.  But I can't help but wonder if
we could make this easier to enforce at 'make syntax-check' time by
tweaking the perl script somehow.

-- 
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/20110217/357ffe5b/attachment-0001.sig>


More information about the libvir-list mailing list