qemuhotplugtest: Free monitor iff successfully initialized

If initializing test monitor in testQemuHotplugCpuPrepare()
fails, the control jumps to error label where
testQemuHotplugCpuDataFree() is called. But since the data->mon
is NULL due to aforementioned failure,
qemuMonitorTestGetMonitor() dereferences a NULL pointer leading
to a SIGSEGV.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
This commit is contained in:
Michal Privoznik 2020-06-27 09:20:21 +02:00
parent d482cf6bef
commit b150fbc4fe

View File

@ -399,9 +399,11 @@ testQemuHotplugCpuDataFree(struct testQemuHotplugCpuData *data)
virObjectUnref(data->vm);
}
mon = qemuMonitorTestGetMonitor(data->mon);
virObjectLock(mon);
qemuMonitorTestFree(data->mon);
if (data->mon) {
mon = qemuMonitorTestGetMonitor(data->mon);
virObjectLock(mon);
qemuMonitorTestFree(data->mon);
}
VIR_FREE(data);
}