[Libvir] [PATCH] remove useless tests before xmlFree

Jim Meyering jim at meyering.net
Tue Apr 29 19:30:39 UTC 2008


I've just fixed a bug in my useless-if-detecting script,
committed in gnulib.  Using that new script with today's
change adding xmlFree to the list exposed a bunch of useless tests.
This first change set removes those tests.

Below it is a separate patch that updates gnulib-related
files, including that script and vc-list-files.
I verified that with these changes "make distcheck" passes.

If no one objects, I'll push these in about 12 hours.

	remove useless tests before xmlFree
	* src/qemu_conf.c (qemudParseDiskXML, qemudParseInterfaceXML):
	(qemudParseInputXML, qemudParseDhcpRangesXML):
	* src/remote_internal.c (doRemoteOpen):
	* src/storage_conf.c (virStoragePoolDefParseDoc):
	* src/xm_internal.c (xenXMParseXMLDisk, xenXMParseXMLVif):
	(xenXMParseXMLToConfig, xenXMAttachInterface):
	* src/xml.c (virDomainParseXMLDiskDesc, virDomainParseXMLIfDesc):
	(virDomainXMLDevID):

Signed-off-by: Jim Meyering <meyering at redhat.com>
---
 src/qemu_conf.c       |   48 ++++++++++++++++--------------------------------
 src/remote_internal.c |    8 ++++----
 src/storage_conf.c    |    3 +--
 src/xm_internal.c     |   42 ++++++++++++++----------------------------
 src/xml.c             |   30 ++++++++++--------------------
 5 files changed, 45 insertions(+), 86 deletions(-)

diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index 07dfe47..a0c4a8f 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -680,14 +680,10 @@ static int qemudParseDiskXML(virConnectPtr conn,
     return 0;

  error:
-    if (type)
-        xmlFree(type);
-    if (target)
-        xmlFree(target);
-    if (source)
-        xmlFree(source);
-    if (device)
-        xmlFree(device);
+    xmlFree(type);
+    xmlFree(target);
+    xmlFree(source);
+    xmlFree(device);
     return -1;
 }

@@ -941,18 +937,12 @@ static int qemudParseInterfaceXML(virConnectPtr conn,
     return 0;

  error:
-    if (network)
-        xmlFree(network);
-    if (address)
-        xmlFree(address);
-    if (port)
-        xmlFree(port);
-    if (ifname)
-        xmlFree(ifname);
-    if (script)
-        xmlFree(script);
-    if (bridge)
-        xmlFree(bridge);
+    xmlFree(network);
+    xmlFree(address);
+    xmlFree(port);
+    xmlFree(ifname);
+    xmlFree(script);
+    xmlFree(bridge);
     return -1;
 }

@@ -1334,18 +1324,14 @@ static int qemudParseInputXML(virConnectPtr conn,
             input->bus = QEMU_INPUT_BUS_USB;
     }

-    if (type)
-        xmlFree(type);
-    if (bus)
-        xmlFree(bus);
+    xmlFree(type);
+    xmlFree(bus);

     return 0;

  error:
-    if (type)
-        xmlFree(type);
-    if (bus)
-        xmlFree(bus);
+    xmlFree(type);
+    xmlFree(bus);

     return -1;
 }
@@ -2860,10 +2846,8 @@ static int qemudParseDhcpRangesXML(virConnectPtr conn,
             free(range);
         }

-        if (start)
-            xmlFree(start);
-        if (end)
-            xmlFree(end);
+        xmlFree(start);
+        xmlFree(end);

         cur = cur->next;
     }
diff --git a/src/remote_internal.c b/src/remote_internal.c
index ef34a3a..70aa5e9 100644
--- a/src/remote_internal.c
+++ b/src/remote_internal.c
@@ -434,9 +434,9 @@ doRemoteOpen (virConnectPtr conn,
     }

 #ifdef HAVE_XMLURI_QUERY_RAW
-    if (uri->query_raw) xmlFree (uri->query_raw);
+    xmlFree (uri->query_raw);
 #else
-    if (uri->query) xmlFree (uri->query);
+    xmlFree (uri->query);
 #endif

     if ((
@@ -464,10 +464,10 @@ doRemoteOpen (virConnectPtr conn,
             transport_str[-1] = '\0';
         }
         /* Remove the username, server name and port number. */
-        if (uri->user) xmlFree (uri->user);
+        xmlFree (uri->user);
         uri->user = 0;

-        if (uri->server) xmlFree (uri->server);
+        xmlFree (uri->server);
         uri->server = 0;

         uri->port = 0;
diff --git a/src/storage_conf.c b/src/storage_conf.c
index 4499ae2..be21d3b 100644
--- a/src/storage_conf.c
+++ b/src/storage_conf.c
@@ -357,8 +357,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,

  cleanup:
     free(uuid);
-    if (type)
-        xmlFree(type);
+    xmlFree(type);
     virStoragePoolDefFree(ret);
     return NULL;
 }
diff --git a/src/xm_internal.c b/src/xm_internal.c
index a70436d..08e3e8e 100644
--- a/src/xm_internal.c
+++ b/src/xm_internal.c
@@ -1657,10 +1657,8 @@ static int xenXMParseXMLDisk(xmlNodePtr node, int hvm, int xendConfigVersion, ch
     }

     if (target == NULL) {
-        if (source != NULL)
-            xmlFree(source);
-        if (device != NULL)
-            xmlFree(device);
+        xmlFree(source);
+        xmlFree(device);
         return (-1);
     }

@@ -1687,10 +1685,8 @@ static int xenXMParseXMLDisk(xmlNodePtr node, int hvm, int xendConfigVersion, ch
     }

     if (source == NULL && !cdrom) {
-        if (target != NULL)
-            xmlFree(target);
-        if (device != NULL)
-            xmlFree(device);
+        xmlFree(target);
+        xmlFree(device);
         return (-1);
     }

@@ -1765,8 +1761,7 @@ static int xenXMParseXMLDisk(xmlNodePtr node, int hvm, int xendConfigVersion, ch
     xmlFree(drvName);
     xmlFree(device);
     xmlFree(target);
-    if(source)
-        xmlFree(source);
+    xmlFree(source);
     *disk = buf;

     return (ret);
@@ -1877,14 +1872,10 @@ static char *xenXMParseXMLVif(virConnectPtr conn, xmlNodePtr node, int hvm) {

  cleanup:
     free(bridge);
-    if (mac != NULL)
-        xmlFree(mac);
-    if (source != NULL)
-        xmlFree(source);
-    if (script != NULL)
-        xmlFree(script);
-    if (ip != NULL)
-        xmlFree(ip);
+    xmlFree(mac);
+    xmlFree(source);
+    xmlFree(script);
+    xmlFree(ip);

     return buf;
 }
@@ -2164,8 +2155,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
                             strcat(val, ",vncdisplay=");
                             strcat(val, portstr);
                         }
-                        if (vncport)
-                            xmlFree(vncport);
+                        xmlFree(vncport);
                         if (vnclisten) {
                             strcat(val, ",vnclisten=");
                             strcat(val, (const char*)vnclisten);
@@ -2310,8 +2300,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
  error:
     if (conf)
         virConfFree(conf);
-    if (prop != NULL)
-        xmlFree(prop);
+    xmlFree(prop);
     xmlXPathFreeObject(obj);
     xmlXPathFreeContext(ctxt);
     if (doc != NULL)
@@ -2960,12 +2949,9 @@ xenXMAttachInterface(virDomainPtr domain, xmlXPathContextPtr ctxt, int hvm,
     goto cleanup;

  node_cleanup:
-    if (node_tmp)
-        xmlFree(node_tmp);
-    if (attr_node)
-        xmlFree(attr_node);
-    if (text_node)
-        xmlFree(text_node);
+    xmlFree(node_tmp);
+    xmlFree(attr_node);
+    xmlFree(text_node);
  cleanup:
     free(type);
     free(source);
diff --git a/src/xml.c b/src/xml.c
index e889cdd..25eba3d 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -1341,16 +1341,11 @@ virDomainParseXMLDiskDesc(virConnectPtr conn, xmlNodePtr node,
     virBufferAddLit(buf, ")");

   cleanup:
-    if (drvType)
-        xmlFree(drvType);
-    if (drvName)
-        xmlFree(drvName);
-    if (device)
-        xmlFree(device);
-    if (target)
-        xmlFree(target);
-    if (source)
-        xmlFree(source);
+    xmlFree(drvType);
+    xmlFree(drvName);
+    xmlFree(device);
+    xmlFree(target);
+    xmlFree(source);
     return (ret);
 }

@@ -1466,14 +1461,10 @@ virDomainParseXMLIfDesc(virConnectPtr conn ATTRIBUTE_UNUSED,
     virBufferAddLit(buf, ")");
     ret = 0;
   error:
-    if (mac != NULL)
-        xmlFree(mac);
-    if (source != NULL)
-        xmlFree(source);
-    if (script != NULL)
-        xmlFree(script);
-    if (ip != NULL)
-        xmlFree(ip);
+    xmlFree(mac);
+    xmlFree(source);
+    xmlFree(script);
+    xmlFree(ip);
     return (ret);
 }

@@ -1953,8 +1944,7 @@ virDomainXMLDevID(virDomainPtr domain, const char *xmldesc, char *class,
   cleanup:
     if (xml != NULL)
         xmlFreeDoc(xml);
-    if (attr != NULL)
-        xmlFree(attr);
+    xmlFree(attr);
     return ret;
 }
 #endif /* WITH_XEN */
--
1.5.5.1.68.gbdcd8






More information about the libvir-list mailing list