mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 15:15:25 +00:00
Fix leaks in udev device add/remove v3
* This patch is a modification of a patch submitted by Nigel Jones. It fixes several memory leaks on device addition/removal: 1. Free the virNodeDeviceDefPtr in udevAddOneDevice if the return value is non-zero 2. Always release the node device reference after the device has been processed. * Refactored for better readability per the suggestion of clalance
This commit is contained in:
parent
77da2487ea
commit
e7f3bad46e
@ -1309,13 +1309,14 @@ static int udevAddOneDevice(struct udev_device *device)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If this is a device change, the old definition will be freed
|
||||||
|
* and the current definition will take its place. */
|
||||||
nodeDeviceLock(driverState);
|
nodeDeviceLock(driverState);
|
||||||
dev = virNodeDeviceAssignDef(&driverState->devs, def);
|
dev = virNodeDeviceAssignDef(&driverState->devs, def);
|
||||||
nodeDeviceUnlock(driverState);
|
nodeDeviceUnlock(driverState);
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1324,6 +1325,10 @@ static int udevAddOneDevice(struct udev_device *device)
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
if (ret != 0) {
|
||||||
|
virNodeDeviceDefFree(def);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1338,15 +1343,17 @@ static int udevProcessDeviceListEntry(struct udev *udev,
|
|||||||
name = udev_list_entry_get_name(list_entry);
|
name = udev_list_entry_get_name(list_entry);
|
||||||
|
|
||||||
device = udev_device_new_from_syspath(udev, name);
|
device = udev_device_new_from_syspath(udev, name);
|
||||||
|
|
||||||
if (device != NULL) {
|
if (device != NULL) {
|
||||||
if (udevAddOneDevice(device) != 0) {
|
if (udevAddOneDevice(device) != 0) {
|
||||||
VIR_INFO("Failed to create node device for udev device '%s'",
|
VIR_INFO("Failed to create node device for udev device '%s'",
|
||||||
name);
|
name);
|
||||||
}
|
}
|
||||||
udev_device_unref(device);
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
udev_device_unref(device);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1454,6 +1461,7 @@ static void udevEventHandleCallback(int watch ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
udev_device_unref(device);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user