[PATCH] Add missing checks for NULL in domain lock manager

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
---
 src/locking/domain_lock.c |   49 ++++++++++++++++++++++++++++++++++----------
 1 files changed, 38 insertions(+), 11 deletions(-)

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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]