qemu: Avoid leak in qemuDomainCheckRemoveOptionalDisk

Coverity complains about event being leaked in
qemuDomainCheckRemoveOptionalDisk. The best fix for it is to remove the
disk directly since we already know its index.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Jiri Denemark 2014-05-15 13:11:12 +02:00
parent 5099084eb3
commit a4693c76f5

View File

@ -2176,11 +2176,11 @@ qemuDomainSetFakeReboot(virQEMUDriverPtr driver,
static int static int
qemuDomainCheckRemoveOptionalDisk(virQEMUDriverPtr driver, qemuDomainCheckRemoveOptionalDisk(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
virDomainDiskDefPtr disk) size_t diskIndex)
{ {
char uuid[VIR_UUID_STRING_BUFLEN]; char uuid[VIR_UUID_STRING_BUFLEN];
virObjectEventPtr event = NULL; virObjectEventPtr event = NULL;
virDomainDiskDefPtr del_disk = NULL; virDomainDiskDefPtr disk = vm->def->disks[diskIndex];
const char *src = virDomainDiskGetSource(disk); const char *src = virDomainDiskGetSource(disk);
virUUIDFormat(vm->def->uuid, uuid); virUUIDFormat(vm->def->uuid, uuid);
@ -2200,13 +2200,8 @@ qemuDomainCheckRemoveOptionalDisk(virQEMUDriverPtr driver,
event = virDomainEventDiskChangeNewFromObj(vm, src, NULL, event = virDomainEventDiskChangeNewFromObj(vm, src, NULL,
disk->info.alias, disk->info.alias,
VIR_DOMAIN_EVENT_DISK_DROP_MISSING_ON_START); VIR_DOMAIN_EVENT_DISK_DROP_MISSING_ON_START);
virDomainDiskRemove(vm->def, diskIndex);
if (!(del_disk = virDomainDiskRemoveByName(vm->def, src))) { virDomainDiskDefFree(disk);
virReportError(VIR_ERR_INVALID_ARG,
_("no source device %s"), src);
return -1;
}
virDomainDiskDefFree(del_disk);
} }
if (event) if (event)
@ -2218,11 +2213,11 @@ qemuDomainCheckRemoveOptionalDisk(virQEMUDriverPtr driver,
static int static int
qemuDomainCheckDiskStartupPolicy(virQEMUDriverPtr driver, qemuDomainCheckDiskStartupPolicy(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
virDomainDiskDefPtr disk, size_t diskIndex,
bool cold_boot) bool cold_boot)
{ {
char uuid[VIR_UUID_STRING_BUFLEN]; char uuid[VIR_UUID_STRING_BUFLEN];
int startupPolicy = disk->startupPolicy; int startupPolicy = vm->def->disks[diskIndex]->startupPolicy;
virUUIDFormat(vm->def->uuid, uuid); virUUIDFormat(vm->def->uuid, uuid);
@ -2244,7 +2239,7 @@ qemuDomainCheckDiskStartupPolicy(virQEMUDriverPtr driver,
break; break;
} }
if (qemuDomainCheckRemoveOptionalDisk(driver, vm, disk) < 0) if (qemuDomainCheckRemoveOptionalDisk(driver, vm, diskIndex) < 0)
goto error; goto error;
return 0; return 0;
@ -2282,11 +2277,11 @@ qemuDomainCheckDiskPresence(virQEMUDriverPtr driver,
{ {
int ret = -1; int ret = -1;
size_t i; size_t i;
virDomainDiskDefPtr disk;
VIR_DEBUG("Checking for disk presence"); VIR_DEBUG("Checking for disk presence");
for (i = vm->def->ndisks; i > 0; i--) { for (i = vm->def->ndisks; i > 0; i--) {
disk = vm->def->disks[i - 1]; size_t idx = i - 1;
virDomainDiskDefPtr disk = vm->def->disks[idx];
const char *path = virDomainDiskGetSource(disk); const char *path = virDomainDiskGetSource(disk);
virStorageFileFormat format = virDomainDiskGetFormat(disk); virStorageFileFormat format = virDomainDiskGetFormat(disk);
virStorageType type = virStorageSourceGetActualType(&disk->src); virStorageType type = virStorageSourceGetActualType(&disk->src);
@ -2308,7 +2303,7 @@ qemuDomainCheckDiskPresence(virQEMUDriverPtr driver,
continue; continue;
if (disk->startupPolicy && if (disk->startupPolicy &&
qemuDomainCheckDiskStartupPolicy(driver, vm, disk, qemuDomainCheckDiskStartupPolicy(driver, vm, idx,
cold_boot) >= 0) { cold_boot) >= 0) {
virResetLastError(); virResetLastError();
continue; continue;