diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 2c557f5bbc6b0d70796ae334126fa4d3a42de410..579563c3f3642bb72768b56ac34e4bc76551684a 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -1294,7 +1294,7 @@ virHostdevUpdateActiveMediatedDevices(virHostdevManagerPtr mgr, virMediatedDeviceSetUsedBy(mdev, drv_name, dom_name); - if (virMediatedDeviceListAdd(mgr->activeMediatedHostdevs, mdev) < 0) + if (virMediatedDeviceListAdd(mgr->activeMediatedHostdevs, &mdev) < 0) goto cleanup; } @@ -1790,7 +1790,7 @@ virHostdevPrepareMediatedDevices(virHostdevManagerPtr mgr, if (!(mdev = virMediatedDeviceNew(src->uuidstr, src->model))) goto cleanup; - if (virMediatedDeviceListAdd(list, mdev) < 0) { + if (virMediatedDeviceListAdd(list, &mdev) < 0) { virMediatedDeviceFree(mdev); goto cleanup; } diff --git a/src/util/virmdev.c b/src/util/virmdev.c index c1499d23873dc3e00e43b076e6153c193ebc89fa..c861d21c9e9a17f2a1c105f36394b7a4b7f2ec32 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -312,16 +312,19 @@ virMediatedDeviceListDispose(void *obj) } +/* The reason for @dev to be double pointer is that VIR_APPEND_ELEMENT clears + * the pointer and we need to clear the original not a copy on the stack + */ int virMediatedDeviceListAdd(virMediatedDeviceListPtr list, - virMediatedDevicePtr dev) + virMediatedDevicePtr *dev) { - if (virMediatedDeviceListFind(list, dev)) { + if (virMediatedDeviceListFind(list, *dev)) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("device %s is already in use"), dev->path); + _("device %s is already in use"), (*dev)->path); return -1; } - return VIR_APPEND_ELEMENT(list->devs, list->count, dev); + return VIR_APPEND_ELEMENT(list->devs, list->count, *dev); } @@ -457,7 +460,7 @@ virMediatedDeviceListMarkDevices(virMediatedDeviceListPtr dst, * - caller is responsible for NOT freeing devices in @src on success * - we're responsible for performing a rollback on failure */ - if (virMediatedDeviceListAdd(dst, mdev) < 0) + if (virMediatedDeviceListAdd(dst, &mdev) < 0) goto rollback; VIR_DEBUG("'%s' added to list of active mediated devices used by '%s'", diff --git a/src/util/virmdev.h b/src/util/virmdev.h index 2f3d6bb84012141b33e84add264504565164f183..8bb46b9c5cfd5cfb28e7e90f2a597afe49010bce 100644 --- a/src/util/virmdev.h +++ b/src/util/virmdev.h @@ -86,7 +86,7 @@ virMediatedDeviceListNew(void); int virMediatedDeviceListAdd(virMediatedDeviceListPtr list, - virMediatedDevicePtr dev); + virMediatedDevicePtr *dev); virMediatedDevicePtr virMediatedDeviceListGet(virMediatedDeviceListPtr list,