mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
vbox: handle errors of virDomainHostdevDefAlloc correctly
The original code ignored errors of virDomainHostdevDefAlloc, however, we should properly do error return from the function if it occurs. The fix pulls out virDomainHostdevDefAlloc from the loop and executes it all together before the loop. So we can easily return on errors without the notion of other memory allocations in the loop. The deallocation code is separated from the allocation code because it will be used by a further patch for fixing other error handlings. Reported-by: Laine Stump <laine@laine.org> Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com>
This commit is contained in:
parent
82b5dd23f3
commit
1ed7e014dd
@ -2269,6 +2269,12 @@ static void vboxHostDeviceGetXMLDesc(vboxGlobalData *data, virDomainDefPtr def,
|
|||||||
if (VIR_ALLOC_N(def->hostdevs, def->nhostdevs) < 0)
|
if (VIR_ALLOC_N(def->hostdevs, def->nhostdevs) < 0)
|
||||||
goto release_filters;
|
goto release_filters;
|
||||||
|
|
||||||
|
for (i = 0; i < def->nhostdevs; i++) {
|
||||||
|
def->hostdevs[i] = virDomainHostdevDefAlloc();
|
||||||
|
if (!def->hostdevs[i])
|
||||||
|
goto release_hostdevs;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < deviceFilters.count; i++) {
|
for (i = 0; i < deviceFilters.count; i++) {
|
||||||
PRBool active = PR_FALSE;
|
PRBool active = PR_FALSE;
|
||||||
IUSBDeviceFilter *deviceFilter = deviceFilters.items[i];
|
IUSBDeviceFilter *deviceFilter = deviceFilters.items[i];
|
||||||
@ -2284,10 +2290,6 @@ static void vboxHostDeviceGetXMLDesc(vboxGlobalData *data, virDomainDefPtr def,
|
|||||||
if (!active)
|
if (!active)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
def->hostdevs[USBFilterCount] = virDomainHostdevDefAlloc();
|
|
||||||
if (!def->hostdevs[USBFilterCount])
|
|
||||||
continue;
|
|
||||||
|
|
||||||
def->hostdevs[USBFilterCount]->mode =
|
def->hostdevs[USBFilterCount]->mode =
|
||||||
VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
|
VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
|
||||||
def->hostdevs[USBFilterCount]->source.subsys.type =
|
def->hostdevs[USBFilterCount]->source.subsys.type =
|
||||||
@ -2322,6 +2324,15 @@ release_controller:
|
|||||||
#else
|
#else
|
||||||
VBOX_RELEASE(USBDeviceFilters);
|
VBOX_RELEASE(USBDeviceFilters);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
release_hostdevs:
|
||||||
|
for (i = 0; i < def->nhostdevs; i++)
|
||||||
|
virDomainHostdevDefFree(def->hostdevs[i]);
|
||||||
|
VIR_FREE(def->hostdevs);
|
||||||
|
|
||||||
|
goto release_filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
|
static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
|
||||||
|
Loading…
Reference in New Issue
Block a user