virdomainjob: add check for callbacks

There may be a case that the callback structure will exist with
no callbacks (following patches). This patch adds check for
specific callbacks before using them.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Kristina Hanicova 2022-09-05 15:57:02 +02:00 committed by Ján Tomko
parent 2378f9d86e
commit 0c3f023045

View File

@ -138,7 +138,7 @@ virDomainObjInitJob(virDomainJobObj *job,
return -1;
}
if (job->cb &&
if (job->cb && job->cb->allocJobPrivate &&
!(job->privateData = job->cb->allocJobPrivate())) {
virCondDestroy(&job->cond);
virCondDestroy(&job->asyncCond);
@ -180,7 +180,7 @@ virDomainObjResetAsyncJob(virDomainJobObj *job)
g_clear_pointer(&job->current, virDomainJobDataFree);
job->apiFlags = 0;
if (job->cb)
if (job->cb && job->cb->resetJobPrivate)
job->cb->resetJobPrivate(job->privateData);
}
@ -206,7 +206,7 @@ virDomainObjPreserveJob(virDomainJobObj *currJob,
job->privateData = g_steal_pointer(&currJob->privateData);
job->apiFlags = currJob->apiFlags;
if (currJob->cb &&
if (currJob->cb && currJob->cb->allocJobPrivate &&
!(currJob->privateData = currJob->cb->allocJobPrivate()))
return -1;
job->cb = currJob->cb;
@ -226,7 +226,7 @@ virDomainObjClearJob(virDomainJobObj *job)
virCondDestroy(&job->cond);
virCondDestroy(&job->asyncCond);
if (job->cb)
if (job->cb && job->cb->freeJobPrivate)
g_clear_pointer(&job->privateData, job->cb->freeJobPrivate);
}