]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
conf: fix memleak in virDomainNetIpParseXML
authorZhang Bo <oscar.zhangbo@huawei.com>
Mon, 27 Apr 2015 06:41:44 +0000 (14:41 +0800)
committerJán Tomko <jtomko@redhat.com>
Mon, 27 Apr 2015 08:04:38 +0000 (10:04 +0200)
use cleanup instead of error, so that the allocated strings could also get freed
when there's no error.

Signed-off-by: Zhang Bo <oscar.zhangbo@huawei.com>
src/conf/domain_conf.c

index fb7594fa77959e8f30fc4f3db7acd19374475711..1b520b9163bbc58022a84f1e185295dde6c8f67b 100644 (file)
@@ -5124,7 +5124,7 @@ static virDomainNetIpDefPtr
 virDomainNetIpParseXML(xmlNodePtr node)
 {
     /* Parse the prefix in every case */
-    virDomainNetIpDefPtr ip = NULL;
+    virDomainNetIpDefPtr ip = NULL, ret = NULL;
     char *prefixStr = NULL;
     unsigned int prefixValue = 0;
     char *familyStr = NULL;
@@ -5140,7 +5140,7 @@ virDomainNetIpParseXML(xmlNodePtr node)
     if (!(address = virXMLPropString(node, "address"))) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
                        _("Missing network address"));
-        goto error;
+        goto cleanup;
     }
 
     familyStr = virXMLPropString(node, "family");
@@ -5152,24 +5152,25 @@ virDomainNetIpParseXML(xmlNodePtr node)
         family = virSocketAddrNumericFamily(address);
 
     if (VIR_ALLOC(ip) < 0)
-        goto error;
+        goto cleanup;
 
     if (virSocketAddrParse(&ip->address, address, family) < 0) {
         virReportError(VIR_ERR_INVALID_ARG,
                        _("Failed to parse IP address: '%s'"),
                        address);
-        goto error;
+        goto cleanup;
     }
     ip->prefix = prefixValue;
 
-    return ip;
+    ret = ip;
+    ip = NULL;
 
error:
cleanup:
     VIR_FREE(prefixStr);
     VIR_FREE(familyStr);
     VIR_FREE(address);
     VIR_FREE(ip);
-    return NULL;
+    return ret;
 }
 
 static int