1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-25 01:34:11 +03:00

qemuhotplugtest: Resolve some memleaks

If testQemuHotplugAttach succeeds, the vm->def steals the dev pointer.
However, not the envelope, which needs to be freed. In addition,
driver.config is allocated, but never freed.
This commit is contained in:
Michal Privoznik 2013-07-18 12:38:02 +02:00
parent b7658f6234
commit 166db595c3

View File

@ -89,6 +89,10 @@ testQemuHotplugAttach(virDomainObjPtr vm,
switch (dev->type) { switch (dev->type) {
case VIR_DOMAIN_DEVICE_CHR: case VIR_DOMAIN_DEVICE_CHR:
ret = qemuDomainAttachChrDevice(&driver, vm, dev->data.chr); ret = qemuDomainAttachChrDevice(&driver, vm, dev->data.chr);
if (!ret) {
/* vm->def stolen dev->data.chr so we ought to avoid freeing it */
dev->data.chr = NULL;
}
break; break;
default: default:
if (virTestGetVerbose()) if (virTestGetVerbose())
@ -214,11 +218,6 @@ testQemuHotplug(const void *data)
switch (test->action) { switch (test->action) {
case ATTACH: case ATTACH:
ret = testQemuHotplugAttach(vm, dev); ret = testQemuHotplugAttach(vm, dev);
if (!ret) {
/* avoid @dev double free on success,
* as @dev is part of vm->def now */
dev = NULL;
}
break; break;
case DETACH: case DETACH:
@ -323,6 +322,7 @@ mymain(void)
virObjectUnref(driver.caps); virObjectUnref(driver.caps);
virObjectUnref(driver.xmlopt); virObjectUnref(driver.xmlopt);
virObjectUnref(driver.config);
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE; return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
} }