qemu: domainjob: Allow InitJob if cb is not set in qemuDomainObjInitJob()

This allows init job even if cb structure is not set. This patch
also includes slight rewriting of the function to make it look
cleaner when freeing resources, by allocating privateData at the
end.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Kristina Hanicova 2022-03-16 15:08:39 +01:00 committed by Michal Privoznik
parent 965f872f92
commit e5c10018c5

View File

@ -189,17 +189,18 @@ qemuDomainObjInitJob(qemuDomainJobObj *job,
memset(job, 0, sizeof(*job));
job->cb = cb;
if (!(job->privateData = job->cb->allocJobPrivate()))
if (virCondInit(&job->cond) < 0)
return -1;
if (virCondInit(&job->cond) < 0) {
job->cb->freeJobPrivate(job->privateData);
if (virCondInit(&job->asyncCond) < 0) {
virCondDestroy(&job->cond);
return -1;
}
if (virCondInit(&job->asyncCond) < 0) {
job->cb->freeJobPrivate(job->privateData);
if (job->cb &&
!(job->privateData = job->cb->allocJobPrivate())) {
virCondDestroy(&job->cond);
virCondDestroy(&job->asyncCond);
return -1;
}