From 2367caa32720708dd012332740873572b44ccafb Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 29 Jan 2008 18:23:43 +0000 Subject: [PATCH] Also detect and remove unnecessary if-before-xmlXPathFreeContext. * build-aux/find-unnecessary-if-before-free: Update regexp. * src/openvz_conf.c: Remove unnecessary "if (P)"-before xmlXPathFreeContext. * src/qemu_conf.c: Likewise. * src/virsh.c: Likewise. * src/xm_internal.c: Likewise. * src/xml.c: Likewise. * tests/xmlrpctest.c: Likewise. --- ChangeLog | 9 +++++++++ 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 +-- 8 files changed, 23 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 483c14a9eb..3723cf12a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ Tue Jan 29 18:39:25 CET 2008 Jim Meyering + Also detect and remove unnecessary if-before-xmlXPathFreeContext. + * build-aux/find-unnecessary-if-before-free: Update regexp. + * src/virsh.c: Remove unnecessary "if (P)"-before xmlXPathFreeContext. + * src/openvz_conf.c: Likewise. + * src/qemu_conf.c: Likewise. + * src/xm_internal.c: Likewise. + * src/xml.c: Likewise. + * tests/xmlrpctest.c: Likewise. + Enable two more tests. * Makefile.cfg (local-checks-to-skip) [sc_cast_of_x_alloc_return_value, sc_cast_of_argument_to_free]: Enable. diff --git a/build-aux/find-unnecessary-if-before-free b/build-aux/find-unnecessary-if-before-free index a95ac24605..0cd38ebc11 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 9084184587..ffb68a54be 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 9886300000..6dc08e0104 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 a1b3e382d6..c09dc8d8a6 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 57d0eb4d57..f452819ef5 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 76ca91cce5..bf1c2ebbde 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 eb75f6436d..e082aab45b 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; -- GitLab