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@xxxxxxxxxx> --- src/conf/domain_conf.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 41963cc..8350fe7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5129,6 +5129,7 @@ virDomainNetIpParseXML(xmlNodePtr node) char *familyStr = NULL; int family = AF_UNSPEC; char *address = NULL; + int ret = -1; if (!(prefixStr = virXMLPropString(node, "prefix")) || (virStrToLong_ui(prefixStr, NULL, 10, &prefixValue) < 0)) { @@ -5139,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"); @@ -5151,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 = 0; - error: + cleanup: VIR_FREE(prefixStr); VIR_FREE(familyStr); VIR_FREE(address); - VIR_FREE(ip); - return NULL; + if (ret) + VIR_FREE(ip); + return ip; } static int -- 1.7.12.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list