"Daniel P. Berrange" <berrange(a)redhat.com> wrote:
On Fri, Jan 25, 2008 at 11:17:09PM +0100, Jim Meyering wrote:
> Given code like if (foo) free (foo); remove the useless "if (foo) " part.
>
> Likewise, given if (foo != NULL) free (foo); remove the useless "if" test.
ACK - already reviewed the previous version of it.
I've added one more free-like function and fixed the
exposed bits. Daniel Veillard assured me that xmlXPathFreeContext
has always worked this way, so we don't need to worry about
old versions that might misbehave.
Signed-off-by: Jim Meyering <meyering(a)redhat.com>
---
build-aux/find-unnecessary-if-before-free | 6 +++---
src/openvz_conf.c | 3 +--
src/qemu_conf.c | 6 ++----
src/virsh.c | 15 +++++----------
src/xm_internal.c | 3 +--
src/xml.c | 3 +--
tests/xmlrpctest.c | 3 +--
7 files changed, 14 insertions(+), 25 deletions(-)
diff --git a/build-aux/find-unnecessary-if-before-free
b/build-aux/find-unnecessary-if-before-free
index a95ac24..0cd38eb 100755
--- a/build-aux/find-unnecessary-if-before-free
+++ b/build-aux/find-unnecessary-if-before-free
@@ -22,7 +22,7 @@ use warnings;
{
if ($line =~
/\b(if\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\)
- \s+(?:sexpr_)?free\s*\(\s*\2\s*\))/sx)
+ \s+(?:xmlXPathFreeContext|(?:sexpr_)?free)\s*\(\s*\2\s*\))/sx)
{
print "$file: $1\n";
$found_match = 1;
@@ -37,6 +37,6 @@ my $foo = <<'EOF';
# The above is to *find* them.
# This adjusts them, removing the unnecessary "if (p)" part.
-git ls-files -z |xargs -0 \
-perl -0x3b -pi -e
's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\)\s+((?:sexpr_)?free\s*\(\s*\1\s*\))/$2/s'
+git ls-files -z --exclude=find-unnecessary-if-before-free |xargs -0 \
+perl -0x3b -pi -e
's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\)\s+((?:xmlXPathFreeContext|(?:sexpr_)?free)\s*\(\s*\1\s*\))/$2/s'
EOF
diff --git a/src/openvz_conf.c b/src/openvz_conf.c
index 9084184..ffb68a5 100644
--- a/src/openvz_conf.c
+++ b/src/openvz_conf.c
@@ -497,8 +497,7 @@ static struct openvz_vm_def
free(prop);
if (obj)
xmlXPathFreeObject(obj);
- if (ctxt)
- xmlXPathFreeContext(ctxt);
+ xmlXPathFreeContext(ctxt);
openvzFreeVMDef(def);
return NULL;
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index 9886300..6dc08e0 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -1382,8 +1382,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
free(prop);
if (obj)
xmlXPathFreeObject(obj);
- if (ctxt)
- xmlXPathFreeContext(ctxt);
+ xmlXPathFreeContext(ctxt);
qemudFreeVMDef(def);
return NULL;
}
@@ -2392,8 +2391,7 @@ static struct qemud_network_def *qemudParseNetworkXML(virConnectPtr
conn,
xmlXPathFreeObject(obj);
if (tmp)
xmlXPathFreeObject(tmp);
- if (ctxt)
- xmlXPathFreeContext(ctxt);
+ xmlXPathFreeContext(ctxt);
qemudFreeNetworkDef(def);
return NULL;
}
diff --git a/src/virsh.c b/src/virsh.c
index a1b3e38..c09dc8d 100644
--- a/src/virsh.c
+++ b/src/virsh.c
@@ -504,8 +504,7 @@ cmdConsole(vshControl * ctl, vshCmd * cmd)
xmlXPathFreeObject(obj);
cleanup:
- if (ctxt)
- xmlXPathFreeContext(ctxt);
+ xmlXPathFreeContext(ctxt);
if (xml)
xmlFreeDoc(xml);
virDomainFree(dom);
@@ -2932,8 +2931,7 @@ cmdVNCDisplay(vshControl * ctl, vshCmd * cmd)
cleanup:
if (obj)
xmlXPathFreeObject(obj);
- if (ctxt)
- xmlXPathFreeContext(ctxt);
+ xmlXPathFreeContext(ctxt);
if (xml)
xmlFreeDoc(xml);
virDomainFree(dom);
@@ -2995,8 +2993,7 @@ cmdTTYConsole(vshControl * ctl, vshCmd * cmd)
cleanup:
if (obj)
xmlXPathFreeObject(obj);
- if (ctxt)
- xmlXPathFreeContext(ctxt);
+ xmlXPathFreeContext(ctxt);
if (xml)
xmlFreeDoc(xml);
virDomainFree(dom);
@@ -3337,8 +3334,7 @@ cmdDetachInterface(vshControl * ctl, vshCmd * cmd)
virDomainFree(dom);
if (obj)
xmlXPathFreeObject(obj);
- if (ctxt)
- xmlXPathFreeContext(ctxt);
+ xmlXPathFreeContext(ctxt);
if (xml)
xmlFreeDoc(xml);
if (xml_buf)
@@ -3611,8 +3607,7 @@ cmdDetachDisk(vshControl * ctl, vshCmd * cmd)
cleanup:
if (obj)
xmlXPathFreeObject(obj);
- if (ctxt)
- xmlXPathFreeContext(ctxt);
+ xmlXPathFreeContext(ctxt);
if (xml)
xmlFreeDoc(xml);
if (xml_buf)
diff --git a/src/xm_internal.c b/src/xm_internal.c
index 57d0eb4..f452819 100644
--- a/src/xm_internal.c
+++ b/src/xm_internal.c
@@ -2273,8 +2273,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char
*xml) {
xmlFree(prop);
if (obj != NULL)
xmlXPathFreeObject(obj);
- if (ctxt != NULL)
- xmlXPathFreeContext(ctxt);
+ xmlXPathFreeContext(ctxt);
if (doc != NULL)
xmlFreeDoc(doc);
return (NULL);
diff --git a/src/xml.c b/src/xml.c
index 76ca91c..bf1c2eb 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -1795,8 +1795,7 @@ virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char
**name,
free(nam);
if (name != NULL)
*name = NULL;
- if (ctxt != NULL)
- xmlXPathFreeContext(ctxt);
+ xmlXPathFreeContext(ctxt);
if (xml != NULL)
xmlFreeDoc(xml);
if (pctxt != NULL)
diff --git a/tests/xmlrpctest.c b/tests/xmlrpctest.c
index eb75f64..e082aab 100644
--- a/tests/xmlrpctest.c
+++ b/tests/xmlrpctest.c
@@ -121,8 +121,7 @@ checkRequestValue(const char *xmlstr, const char *xpath, int type,
void *expecte
error:
if (obj)
xmlXPathFreeObject(obj);
- if (ctxt)
- xmlXPathFreeContext(ctxt);
+ xmlXPathFreeContext(ctxt);
if (xml)
xmlFreeDoc(xml);
return ret;
--
1.5.4.rc5.1.g0fa73