From d58c146a4f083c2d86ac5a4dd450f63751a36913 Mon Sep 17 00:00:00 2001 From: Pavel Hrdina Date: Fri, 7 Apr 2017 13:43:25 +0200 Subject: [PATCH] qemu: fix memory leak and check mdevPath Signed-off-by: Pavel Hrdina --- src/qemu/qemu_command.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 445c696d6e..b3c26d2d80 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5229,11 +5229,13 @@ qemuBuildHostdevMediatedDevStr(const virDomainDef *def, virBuffer buf = VIR_BUFFER_INITIALIZER; virDomainHostdevSubsysMediatedDevPtr mdevsrc = &dev->source.subsys.u.mdev; char *ret = NULL; + char *mdevPath = NULL; + + if (!(mdevPath = virMediatedDeviceGetSysfsPath(mdevsrc->uuidstr))) + goto cleanup; virBufferAddLit(&buf, "vfio-pci"); - virBufferAsprintf(&buf, ",id=%s,sysfsdev=%s", - dev->info->alias, - virMediatedDeviceGetSysfsPath(mdevsrc->uuidstr)); + virBufferAsprintf(&buf, ",id=%s,sysfsdev=%s", dev->info->alias, mdevPath); if (qemuBuildDeviceAddressStr(&buf, def, dev->info, qemuCaps) < 0) goto cleanup; @@ -5244,6 +5246,7 @@ qemuBuildHostdevMediatedDevStr(const virDomainDef *def, ret = virBufferContentAndReset(&buf); cleanup: + VIR_FREE(mdevPath); virBufferFreeAndReset(&buf); return ret; }