mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
Free resources on error in udev startup
* The udev driver didn't properly free resources that it allocates when setting up the 'computer' device in the error case.
This commit is contained in:
parent
056623f3d7
commit
b978f31a93
@ -1440,33 +1440,15 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int udevSetupSystemDev(void)
|
static void
|
||||||
|
udevGetDMIData(union _virNodeDevCapData *data)
|
||||||
{
|
{
|
||||||
virNodeDeviceDefPtr def = NULL;
|
|
||||||
virNodeDeviceObjPtr dev = NULL;
|
|
||||||
struct udev *udev = NULL;
|
struct udev *udev = NULL;
|
||||||
struct udev_device *device = NULL;
|
struct udev_device *device = NULL;
|
||||||
union _virNodeDevCapData *data = NULL;
|
|
||||||
char *tmp = NULL;
|
char *tmp = NULL;
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if (VIR_ALLOC(def) != 0) {
|
|
||||||
virReportOOMError();
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
def->name = strdup("computer");
|
|
||||||
if (def->name == NULL) {
|
|
||||||
virReportOOMError();
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (VIR_ALLOC(def->caps) != 0) {
|
|
||||||
virReportOOMError();
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
udev = udev_monitor_get_udev(DRV_STATE_UDEV_MONITOR(driverState));
|
udev = udev_monitor_get_udev(DRV_STATE_UDEV_MONITOR(driverState));
|
||||||
|
|
||||||
device = udev_device_new_from_syspath(udev, DMI_DEVPATH);
|
device = udev_device_new_from_syspath(udev, DMI_DEVPATH);
|
||||||
if (device == NULL) {
|
if (device == NULL) {
|
||||||
device = udev_device_new_from_syspath(udev, DMI_DEVPATH_FALLBACK);
|
device = udev_device_new_from_syspath(udev, DMI_DEVPATH_FALLBACK);
|
||||||
@ -1477,8 +1459,6 @@ static int udevSetupSystemDev(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data = &def->caps->data;
|
|
||||||
|
|
||||||
if (udevGetStringSysfsAttr(device,
|
if (udevGetStringSysfsAttr(device,
|
||||||
"product_name",
|
"product_name",
|
||||||
&data->system.product_name) == PROPERTY_ERROR) {
|
&data->system.product_name) == PROPERTY_ERROR) {
|
||||||
@ -1508,8 +1488,7 @@ static int udevSetupSystemDev(void)
|
|||||||
&tmp) == PROPERTY_ERROR) {
|
&tmp) == PROPERTY_ERROR) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
virUUIDParse(tmp, def->caps->data.system.hardware.uuid);
|
virUUIDParse(tmp, data->system.hardware.uuid);
|
||||||
VIR_FREE(tmp);
|
|
||||||
|
|
||||||
if (udevGetStringSysfsAttr(device,
|
if (udevGetStringSysfsAttr(device,
|
||||||
"bios_vendor",
|
"bios_vendor",
|
||||||
@ -1530,12 +1509,42 @@ static int udevSetupSystemDev(void)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
VIR_FREE(tmp);
|
||||||
|
if (device != NULL) {
|
||||||
udev_device_unref(device);
|
udev_device_unref(device);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int udevSetupSystemDev(void)
|
||||||
|
{
|
||||||
|
virNodeDeviceDefPtr def = NULL;
|
||||||
|
virNodeDeviceObjPtr dev = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (VIR_ALLOC(def) != 0) {
|
||||||
|
virReportOOMError();
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
def->name = strdup("computer");
|
||||||
|
if (def->name == NULL) {
|
||||||
|
virReportOOMError();
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VIR_ALLOC(def->caps) != 0) {
|
||||||
|
virReportOOMError();
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
udevGetDMIData(&def->caps->data);
|
||||||
|
|
||||||
dev = virNodeDeviceAssignDef(&driverState->devs, def);
|
dev = virNodeDeviceAssignDef(&driverState->devs, def);
|
||||||
if (dev == NULL) {
|
if (dev == NULL) {
|
||||||
VIR_ERROR("Failed to create device for '%s'", def->name);
|
VIR_ERROR("Failed to create device for '%s'", def->name);
|
||||||
virNodeDeviceDefFree(def);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1544,6 +1553,10 @@ static int udevSetupSystemDev(void)
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
if (ret == -1) {
|
||||||
|
virNodeDeviceDefFree(def);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user