mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
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: Zhang Bo <oscar.zhangbo@huawei.com>
This commit is contained in:
parent
768ec8c16d
commit
7e3faa0959
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user