提交 7e3faa09 编写于 作者: Z Zhang Bo 提交者: Ján Tomko

conf: fix memleak in virDomainNetIpParseXML

use cleanup instead of error, so that the allocated strings could also get freed
when there's no error.
Signed-off-by: NZhang Bo <oscar.zhangbo@huawei.com>
上级 768ec8c1
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册