diff --git a/ChangeLog b/ChangeLog index 483c14a9ebde8f979dac9376a9907e2c3ef27b55..3723cf12a1595a575b78e90d97d1ca3ce8b9d4a8 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 a95ac246050fae5d827a17fe5a5742191f3ae0b3..0cd38ebc1160c2f9af0b49b4ba267d73a615776c 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 908418458741798d854aeea939874d70d259bb32..ffb68a54be59622e6cc10236d70b24cc03b62ddc 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 9886300000c47f0bd3d3a04b2cd3390e9b474f60..6dc08e0104314439b79c5daa1d18fecb8f0e756b 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 a1b3e382d6f7d3dbb794e4a6a1dda3669a0eeec6..c09dc8d8a6318a289665f18a207c642506dc876c 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 57d0eb4d57f3ef2049c3b20c36ec3fc9c3b763c1..f452819ef54afada7d7ef98f8394d029d1e1bdc1 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 76ca91cce5a74b43dadedf5ffdc1f59bfba9fad2..bf1c2ebbde19d418d54ffff894376e7c92055081 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 eb75f6436db9e057ca0c7af4a28b4e60f994fd55..e082aab45b01ac41a69ebe37446443815d1f643d 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;