
On Thu, Mar 19, 2015 at 18:40:36 -0400, John Ferlan wrote:
On 03/17/2015 10:20 AM, Peter Krempa wrote:
Add code to hot-add memory devices to running qemu instances. ---
Notes: Version 3: - added comment to clarify that @mem is always consumed by qemuDomainAttachMemory Version 2: - no change
Version 2: - no change
src/qemu/qemu_command.c | 4 +-- src/qemu/qemu_command.h | 15 ++++++++ src/qemu/qemu_driver.c | 5 ++- src/qemu/qemu_hotplug.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_hotplug.h | 3 ++ 5 files changed, 119 insertions(+), 3 deletions(-)
@@ -1672,6 +1672,101 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver,
...
}
+/** + * qemuDomainAttachMemory: + * @driver: qemu driver data + * @vm: VM object + * @mem: Definition of the memory device to be attached. @mem is always consumed + * + * Attaches memory device described by @mem to domain @vm. + * + * Returns 0 on success -1 on error. + */ +int +qemuDomainAttachMemory(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainMemoryDefPtr mem) +{ + qemuDomainObjPrivatePtr priv = vm->privateData; + virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); + char *devstr = NULL; + char *objalias = NULL; + const char *backendType; + virJSONValuePtr props = NULL; + int id; + int ret = -1; + + if (virAsprintf(&mem->info.alias, "dimm%zu", vm->def->nmems) < 0) + goto cleanup; + + if (virAsprintf(&objalias, "mem%s", mem->info.alias) < 0) + goto cleanup; + + if (!(devstr = qemuBuildMemoryDeviceStr(mem, priv->qemuCaps))) + goto cleanup; + + qemuDomainMemoryDeviceAlignSize(mem); + + if (qemuBuildMemoryBackendStr(mem->size, mem->pagesize, + mem->targetNode, mem->sourceNodes, NULL, + vm->def, priv->qemuCaps, cfg, + &backendType, &props, true) < 0)
Coverity determines that qemuBuildMemoryBackendStr can return props here with a -1 return and thus leak props
That's because qemuBuildMemoryBackendStr sets the returned *backendProps and sets the local props to NULL before the (!hugepages) code which if it fails won't cause 'props' to be free'd properly
Adding the virJSONValueFree(props); makes Coverity happy again.
I'll fix qemuBuildMemoryBackendStr separately rather than adding a pseudo-hack that would violate the style we are using for functions that return via argument. Peter