virMediatedDeviceListAdd calls VIR_APPEND_ELEMENT which normally clears
the element to be added, thus the pointer must not be used afterwards,
but because the pointer here is passed by value, what gets cleared is
a copy of the original pointer that got created on the stack
automatically when calling the function. The fact that it works now is
just a coincidence and a bug in virMediatedDeviceListAdd that needs to
be fixed in a separate commit. Therefore, use a local variable to hold
data, rather than accessing the pointer later.
Signed-off-by: Erik Skultety <eskultet(a)redhat.com>
---
src/util/virmdev.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/util/virmdev.c b/src/util/virmdev.c
index 2a1ade739..c1499d238 100644
--- a/src/util/virmdev.c
+++ b/src/util/virmdev.c
@@ -447,20 +447,21 @@ virMediatedDeviceListMarkDevices(virMediatedDeviceListPtr dst,
virObjectLock(dst);
for (i = 0; i < count; i++) {
virMediatedDevicePtr mdev = virMediatedDeviceListGet(src, i);
+ const char *mdev_path = mdev->path;
if (virMediatedDeviceIsUsed(mdev, dst) ||
virMediatedDeviceSetUsedBy(mdev, drvname, domname) < 0)
goto cleanup;
/* Copy mdev references to the driver list:
- * - caller is responsible for NOT freeing devices in @list on success
+ * - 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)
goto rollback;
VIR_DEBUG("'%s' added to list of active mediated devices used by
'%s'",
- mdev->path, domname);
+ mdev_path, domname);
}
ret = 0;
--
2.12.2