vbox: refactor vboxNetworkGetXMLDesc a bit

Error out on allocation failure to reduce the nesting.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Ján Tomko 2020-10-02 20:02:48 +02:00
parent 5ee7714b57
commit 281ccec246
1 changed files with 49 additions and 53 deletions

View File

@ -821,14 +821,18 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags)
networkNameUtf16,
&dhcpServer);
if (dhcpServer) {
ipdef->nranges = 1;
if (VIR_ALLOC_N(ipdef->ranges, ipdef->nranges) >= 0) {
PRUnichar *ipAddressUtf16 = NULL;
PRUnichar *networkMaskUtf16 = NULL;
PRUnichar *fromIPAddressUtf16 = NULL;
PRUnichar *toIPAddressUtf16 = NULL;
PRUnichar *macAddressUtf16 = NULL;
bool errorOccurred = false;
ipdef->nranges = 1;
if (VIR_ALLOC_N(ipdef->ranges, ipdef->nranges) < 0)
goto cleanup;
gVBoxAPI.UIDHCPServer.GetIPAddress(dhcpServer, &ipAddressUtf16);
gVBoxAPI.UIDHCPServer.GetNetworkMask(dhcpServer, &networkMaskUtf16);
gVBoxAPI.UIDHCPServer.GetLowerIP(dhcpServer, &fromIPAddressUtf16);
@ -855,15 +859,10 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags)
if (errorOccurred)
goto cleanup;
} else {
ipdef->nranges = 0;
}
ipdef->nhosts = 1;
if (VIR_ALLOC_N(ipdef->hosts, ipdef->nhosts) >= 0) {
PRUnichar *macAddressUtf16 = NULL;
PRUnichar *ipAddressUtf16 = NULL;
bool errorOccurred = false;
if (VIR_ALLOC_N(ipdef->hosts, ipdef->nhosts) < 0)
goto cleanup;
ipdef->hosts[0].name = g_strdup(network->name);
gVBoxAPI.UIHNInterface.GetHardwareAddress(networkInterface, &macAddressUtf16);
@ -881,9 +880,6 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags)
if (errorOccurred)
goto cleanup;
} else {
ipdef->nhosts = 0;
}
} else {
PRUnichar *networkMaskUtf16 = NULL;
PRUnichar *ipAddressUtf16 = NULL;