Add missing checks for NULL in domain lock manager

The domain lock manager forgot to include a bunch of checks
for NULL which could occur on OOM

* src/locking/domain_lock.c: Add checks for NULL
This commit is contained in:
Daniel P. Berrange 2011-06-14 09:05:54 +01:00
parent a81822063d
commit cc743e2314

View File

@ -157,10 +157,13 @@ int virDomainLockProcessStart(virLockManagerPluginPtr plugin,
virDomainObjPtr dom, virDomainObjPtr dom,
bool paused) bool paused)
{ {
virLockManagerPtr lock = virDomainLockManagerNew(plugin, dom, true); virLockManagerPtr lock;
int ret; int ret;
int flags = VIR_LOCK_MANAGER_ACQUIRE_RESTRICT; int flags = VIR_LOCK_MANAGER_ACQUIRE_RESTRICT;
if (!(lock = virDomainLockManagerNew(plugin, dom, true)))
return -1;
if (paused) if (paused)
flags |= VIR_LOCK_MANAGER_ACQUIRE_REGISTER_ONLY; flags |= VIR_LOCK_MANAGER_ACQUIRE_REGISTER_ONLY;
@ -175,9 +178,13 @@ int virDomainLockProcessPause(virLockManagerPluginPtr plugin,
virDomainObjPtr dom, virDomainObjPtr dom,
char **state) char **state)
{ {
virLockManagerPtr lock = virDomainLockManagerNew(plugin, dom, true); virLockManagerPtr lock;
int ret = virLockManagerRelease(lock, state, 0); int ret;
if (!(lock = virDomainLockManagerNew(plugin, dom, true)))
return -1;
ret = virLockManagerRelease(lock, state, 0);
virLockManagerFree(lock); virLockManagerFree(lock);
return ret; return ret;
@ -187,9 +194,13 @@ int virDomainLockProcessResume(virLockManagerPluginPtr plugin,
virDomainObjPtr dom, virDomainObjPtr dom,
const char *state) const char *state)
{ {
virLockManagerPtr lock = virDomainLockManagerNew(plugin, dom, true); virLockManagerPtr lock;
int ret = virLockManagerAcquire(lock, state, 0); int ret;
if (!(lock = virDomainLockManagerNew(plugin, dom, true)))
return -1;
ret = virLockManagerAcquire(lock, state, 0);
virLockManagerFree(lock); virLockManagerFree(lock);
return ret; return ret;
@ -199,9 +210,13 @@ int virDomainLockProcessInquire(virLockManagerPluginPtr plugin,
virDomainObjPtr dom, virDomainObjPtr dom,
char **state) char **state)
{ {
virLockManagerPtr lock = virDomainLockManagerNew(plugin, dom, true); virLockManagerPtr lock;
int ret = virLockManagerInquire(lock, state, 0); int ret;
if (!(lock = virDomainLockManagerNew(plugin, dom, true)))
return -1;
ret = virLockManagerInquire(lock, state, 0);
virLockManagerFree(lock); virLockManagerFree(lock);
return ret; return ret;
@ -212,9 +227,12 @@ int virDomainLockDiskAttach(virLockManagerPluginPtr plugin,
virDomainObjPtr dom, virDomainObjPtr dom,
virDomainDiskDefPtr disk) virDomainDiskDefPtr disk)
{ {
virLockManagerPtr lock = virDomainLockManagerNew(plugin, dom, false); virLockManagerPtr lock;
int ret = -1; int ret = -1;
if (!(lock = virDomainLockManagerNew(plugin, dom, false)))
return -1;
if (virDomainLockManagerAddDisk(lock, disk) < 0) if (virDomainLockManagerAddDisk(lock, disk) < 0)
goto cleanup; goto cleanup;
@ -233,9 +251,12 @@ int virDomainLockDiskDetach(virLockManagerPluginPtr plugin,
virDomainObjPtr dom, virDomainObjPtr dom,
virDomainDiskDefPtr disk) virDomainDiskDefPtr disk)
{ {
virLockManagerPtr lock = virDomainLockManagerNew(plugin, dom, false); virLockManagerPtr lock;
int ret = -1; int ret = -1;
if (!(lock = virDomainLockManagerNew(plugin, dom, false)))
return -1;
if (virDomainLockManagerAddDisk(lock, disk) < 0) if (virDomainLockManagerAddDisk(lock, disk) < 0)
goto cleanup; goto cleanup;
@ -255,9 +276,12 @@ int virDomainLockLeaseAttach(virLockManagerPluginPtr plugin,
virDomainObjPtr dom, virDomainObjPtr dom,
virDomainLeaseDefPtr lease) virDomainLeaseDefPtr lease)
{ {
virLockManagerPtr lock = virDomainLockManagerNew(plugin, dom, false); virLockManagerPtr lock;
int ret = -1; int ret = -1;
if (!(lock = virDomainLockManagerNew(plugin, dom, false)))
return -1;
if (virDomainLockManagerAddLease(lock, lease) < 0) if (virDomainLockManagerAddLease(lock, lease) < 0)
goto cleanup; goto cleanup;
@ -276,9 +300,12 @@ int virDomainLockLeaseDetach(virLockManagerPluginPtr plugin,
virDomainObjPtr dom, virDomainObjPtr dom,
virDomainLeaseDefPtr lease) virDomainLeaseDefPtr lease)
{ {
virLockManagerPtr lock = virDomainLockManagerNew(plugin, dom, false); virLockManagerPtr lock;
int ret = -1; int ret = -1;
if (!(lock = virDomainLockManagerNew(plugin, dom, false)))
return -1;
if (virDomainLockManagerAddLease(lock, lease) < 0) if (virDomainLockManagerAddLease(lock, lease) < 0)
goto cleanup; goto cleanup;