1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

vboxDumpNetwork: allocate the network too

Move the allocation from vboxDumpNetworks inside vboxDumpNetwork.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Ján Tomko 2018-02-23 13:45:21 +01:00
parent 774bedc496
commit a8a2d7db67

View File

@ -3694,14 +3694,18 @@ vboxDumpSharedFolders(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine
return ret; return ret;
} }
static void static virDomainNetDefPtr
vboxDumpNetwork(virDomainNetDefPtr net, vboxDriverPtr data, INetworkAdapter *adapter) vboxDumpNetwork(vboxDriverPtr data, INetworkAdapter *adapter)
{ {
PRUint32 attachmentType = NetworkAttachmentType_Null; PRUint32 attachmentType = NetworkAttachmentType_Null;
PRUint32 adapterType = NetworkAdapterType_Null; PRUint32 adapterType = NetworkAdapterType_Null;
PRUnichar *MACAddressUtf16 = NULL; PRUnichar *MACAddressUtf16 = NULL;
char *MACAddress = NULL; char *MACAddress = NULL;
char macaddr[VIR_MAC_STRING_BUFLEN] = {0}; char macaddr[VIR_MAC_STRING_BUFLEN] = {0};
virDomainNetDefPtr net = NULL;
if (VIR_ALLOC(net) < 0)
return NULL;
gVBoxAPI.UINetworkAdapter.GetAttachmentType(adapter, &attachmentType); gVBoxAPI.UINetworkAdapter.GetAttachmentType(adapter, &attachmentType);
if (attachmentType == NetworkAttachmentType_NAT) { if (attachmentType == NetworkAttachmentType_NAT) {
@ -3787,6 +3791,7 @@ vboxDumpNetwork(virDomainNetDefPtr net, vboxDriverPtr data, INetworkAdapter *ada
VBOX_UTF16_FREE(MACAddressUtf16); VBOX_UTF16_FREE(MACAddressUtf16);
VBOX_UTF8_FREE(MACAddress); VBOX_UTF8_FREE(MACAddress);
return net;
} }
static void static void
@ -3813,15 +3818,13 @@ vboxDumpNetworks(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine, PRU
} }
/* Allocate memory for the networkcards which are enabled */ /* Allocate memory for the networkcards which are enabled */
if ((def->nnets > 0) && (VIR_ALLOC_N(def->nets, def->nnets) >= 0)) { if (def->nnets > 0)
for (i = 0; i < def->nnets; i++) ignore_value(VIR_ALLOC_N(def->nets, def->nnets));
ignore_value(VIR_ALLOC(def->nets[i]));
}
/* Now get the details about the network cards here */ /* Now get the details about the network cards here */
for (i = 0; netAdpIncCnt < def->nnets && i < networkAdapterCount; i++) { for (i = 0; netAdpIncCnt < def->nnets && i < networkAdapterCount; i++) {
INetworkAdapter *adapter = NULL; INetworkAdapter *adapter = NULL;
virDomainNetDefPtr net = def->nets[netAdpIncCnt]; virDomainNetDefPtr net = NULL;
PRBool enabled = PR_FALSE; PRBool enabled = PR_FALSE;
gVBoxAPI.UIMachine.GetNetworkAdapter(machine, i, &adapter); gVBoxAPI.UIMachine.GetNetworkAdapter(machine, i, &adapter);
@ -3829,9 +3832,8 @@ vboxDumpNetworks(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine, PRU
gVBoxAPI.UINetworkAdapter.GetEnabled(adapter, &enabled); gVBoxAPI.UINetworkAdapter.GetEnabled(adapter, &enabled);
if (enabled) { if (enabled) {
vboxDumpNetwork(net, data, adapter); net = vboxDumpNetwork(data, adapter);
def->nets[netAdpIncCnt++] = net;
netAdpIncCnt++;
} }
VBOX_RELEASE(adapter); VBOX_RELEASE(adapter);