qemu: Add and use qemuProcessEventFree for freeing qemuProcessEvents

Add and use qemuProcessEventFree for freeing qemuProcessEvents. This
is less error-prone as the compiler can help us make sure that for
every new enumeration value of qemuProcessEventType the
qemuProcessEventFree function has to be adapted.

All process*Event functions are *only* called by
qemuProcessHandleEvent and this function does the freeing by itself
with qemuProcessEventFree. This means that an explicit freeing of
processEvent->data is no longer required in each process*Event
handler.

The effectiveness of this change is also demonstrated by the fact that
it fixes a memory leak of the panic info data in
qemuProcessHandleGuestPanic.

Reported-by: Wang Dong <dongdwdw@linux.vnet.ibm.com>
Signed-off-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Marc Hartmayer 2018-02-02 13:13:46 +01:00 committed by Michal Privoznik
parent 7db455cebd
commit 07dcad41a2
4 changed files with 41 additions and 29 deletions

View File

@ -11384,3 +11384,28 @@ qemuDomainPrepareDiskSource(virConnectPtr conn,
return 0;
}
void
qemuProcessEventFree(struct qemuProcessEvent *event)
{
if (!event)
return;
switch (event->eventType) {
case QEMU_PROCESS_EVENT_GUESTPANIC:
qemuMonitorEventPanicInfoFree(event->data);
break;
case QEMU_PROCESS_EVENT_WATCHDOG:
case QEMU_PROCESS_EVENT_DEVICE_DELETED:
case QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED:
case QEMU_PROCESS_EVENT_SERIAL_CHANGED:
case QEMU_PROCESS_EVENT_BLOCK_JOB:
case QEMU_PROCESS_EVENT_MONITOR_EOF:
VIR_FREE(event->data);
break;
case QEMU_PROCESS_EVENT_LAST:
break;
}
VIR_FREE(event);
}

View File

@ -445,6 +445,8 @@ struct qemuProcessEvent {
void *data;
};
void qemuProcessEventFree(struct qemuProcessEvent *event);
typedef struct _qemuDomainLogContext qemuDomainLogContext;
typedef qemuDomainLogContext *qemuDomainLogContextPtr;

View File

@ -4183,8 +4183,8 @@ processWatchdogEvent(virQEMUDriverPtr driver,
qemuDomainObjEndAsyncJob(driver, vm);
cleanup:
VIR_FREE(dumpfile);
virObjectUnref(cfg);
VIR_FREE(dumpfile);
}
static int
@ -4309,7 +4309,6 @@ processGuestPanicEvent(virQEMUDriverPtr driver,
qemuDomainRemoveInactiveJob(driver, vm);
cleanup:
qemuMonitorEventPanicInfoFree(info);
virObjectUnref(cfg);
}
@ -4317,7 +4316,7 @@ processGuestPanicEvent(virQEMUDriverPtr driver,
static void
processDeviceDeletedEvent(virQEMUDriverPtr driver,
virDomainObjPtr vm,
char *devAlias)
const char *devAlias)
{
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
virDomainDeviceDef dev;
@ -4351,7 +4350,6 @@ processDeviceDeletedEvent(virQEMUDriverPtr driver,
qemuDomainObjEndJob(driver, vm);
cleanup:
VIR_FREE(devAlias);
virObjectUnref(cfg);
}
@ -4547,7 +4545,7 @@ syncNicRxFilterMulticast(char *ifname,
static void
processNicRxFilterChangedEvent(virQEMUDriverPtr driver,
virDomainObjPtr vm,
char *devAlias)
const char *devAlias)
{
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
qemuDomainObjPrivatePtr priv = vm->privateData;
@ -4648,7 +4646,6 @@ processNicRxFilterChangedEvent(virQEMUDriverPtr driver,
cleanup:
virNetDevRxFilterFree(hostFilter);
virNetDevRxFilterFree(guestFilter);
VIR_FREE(devAlias);
virObjectUnref(cfg);
}
@ -4656,7 +4653,7 @@ processNicRxFilterChangedEvent(virQEMUDriverPtr driver,
static void
processSerialChangedEvent(virQEMUDriverPtr driver,
virDomainObjPtr vm,
char *devAlias,
const char *devAlias,
bool connected)
{
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
@ -4735,23 +4732,21 @@ processSerialChangedEvent(virQEMUDriverPtr driver,
qemuDomainObjEndJob(driver, vm);
cleanup:
VIR_FREE(devAlias);
virObjectUnref(cfg);
}
static void
processBlockJobEvent(virQEMUDriverPtr driver,
virDomainObjPtr vm,
char *diskAlias,
const char *diskAlias,
int type,
int status)
{
virDomainDiskDefPtr disk;
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
goto cleanup;
return;
if (!virDomainObjIsActive(vm)) {
VIR_DEBUG("Domain is not running");
@ -4763,8 +4758,6 @@ processBlockJobEvent(virQEMUDriverPtr driver,
endjob:
qemuDomainObjEndJob(driver, vm);
cleanup:
VIR_FREE(diskAlias);
}
@ -4856,7 +4849,7 @@ static void qemuProcessEventHandler(void *data, void *opaque)
}
virDomainObjEndAPI(&vm);
VIR_FREE(processEvent);
qemuProcessEventFree(processEvent);
}

View File

@ -303,7 +303,7 @@ qemuProcessHandleMonitorEOF(qemuMonitorPtr mon,
if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
ignore_value(virObjectUnref(vm));
VIR_FREE(processEvent);
qemuProcessEventFree(processEvent);
goto cleanup;
}
@ -917,7 +917,7 @@ qemuProcessHandleWatchdog(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
if (!virObjectUnref(vm))
vm = NULL;
VIR_FREE(processEvent);
qemuProcessEventFree(processEvent);
}
}
}
@ -1047,9 +1047,7 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virObjectUnlock(vm);
return 0;
error:
if (processEvent)
VIR_FREE(processEvent->data);
VIR_FREE(processEvent);
qemuProcessEventFree(processEvent);
goto cleanup;
}
@ -1355,7 +1353,7 @@ qemuProcessHandleGuestPanic(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
if (virThreadPoolSendJob(driver->workerPool, 0, processEvent) < 0) {
if (!virObjectUnref(vm))
vm = NULL;
VIR_FREE(processEvent);
qemuProcessEventFree(processEvent);
}
cleanup:
@ -1403,9 +1401,7 @@ qemuProcessHandleDeviceDeleted(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virObjectUnlock(vm);
return 0;
error:
if (processEvent)
VIR_FREE(processEvent->data);
VIR_FREE(processEvent);
qemuProcessEventFree(processEvent);
goto cleanup;
}
@ -1551,9 +1547,7 @@ qemuProcessHandleNicRxFilterChanged(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virObjectUnlock(vm);
return 0;
error:
if (processEvent)
VIR_FREE(processEvent->data);
VIR_FREE(processEvent);
qemuProcessEventFree(processEvent);
goto cleanup;
}
@ -1593,9 +1587,7 @@ qemuProcessHandleSerialChanged(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virObjectUnlock(vm);
return 0;
error:
if (processEvent)
VIR_FREE(processEvent->data);
VIR_FREE(processEvent);
qemuProcessEventFree(processEvent);
goto cleanup;
}