b/src/node_device/node_device_udev.c
@@ -1107,7 +1107,7 @@ static int udevAddOneDevice(struct udev_device *device)
virNodeDeviceDefPtr def = NULL;
virNodeDeviceObjPtr dev = NULL;
virObjectEventPtr event = NULL;
- bool new_device;
+ bool new_device = true;
int ret = -1;
if (VIR_ALLOC(def) != 0)
@@ -1132,13 +1132,16 @@ static int udevAddOneDevice(struct udev_device *device)
goto cleanup;
dev = virNodeDeviceFindByName(&driver->devs, def->name);
- new_device = !!dev;
- if (new_device)
- nodeDeviceUnlock();
+ if (dev) {
+ virNodeDeviceObjUnlock(dev);
+ new_device = false;
+ }
/* If this is a device change, the old definition will be freed
* and the current definition will take its place. */
dev = virNodeDeviceAssignDef(&driver->devs, def);
+ if (dev == NULL)
+ goto cleanup;
if (new_device)
event = virNodeDeviceEventLifecycleNew(dev->def->name,