[libvirt] [PATCH] lxcFreezeContainer: avoid test-after-deref of never-NULL pointer

Jim Meyering jim at meyering.net
Mon May 17 17:40:55 UTC 2010


Eric Blake wrote:
> On 05/17/2010 11:22 AM, Jim Meyering wrote:
>> This addresses another coverity-spotted "flaw".
>> However, since "cgroup" is never NULL after that initial "if" stmt,
>> the only penalty is that the useless cleanup test would make a reviewer
>> try to figure out how cgroup could be NULL there.
>
> ACK.

Thanks.

>>  cleanup:
>> -    if (cgroup)
>> -        virCgroupFree(&cgroup);
>> +    virCgroupFree(&cgroup);
>
> Is this something that the useless-if-before-free test could have
> caught, rather than waiting for coverity?

Very good idea.
Here's a patch to do that.
With this, "make sc_avoid_if_before_free" (part of make syntax-check)
will now prevent any new useless checks.
The above was the sole offender.

>From 387d3649eed2644576733febc53641228bb93257 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Mon, 17 May 2010 19:38:35 +0200
Subject: [PATCH] maint: add virCgroupFree to the list of free-like functions

This makes the useless-if-before-free test in maint.mk spot
uses of virCgroupFree just like it does for free and the other
listed functions.
* cfg.mk (useless_free_options): Add virCgroupFree.
Prompted by suggestion from Eric Blake.
---
 cfg.mk |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index 7773d06..0b281a5 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -64,10 +64,11 @@ local-checks-to-skip =			\
   sc_makefile_check			\
   sc_useless_cpp_parens

 useless_free_options =		\
   --name=sexpr_free		\
+  --name=virCgroupFree		\
   --name=VIR_FREE		\
   --name=xmlFree		\
   --name=xmlXPathFreeContext	\
   --name=virDomainDefFree	\
   --name=xmlXPathFreeObject
--
1.7.1.250.g7d1e8




More information about the libvir-list mailing list