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

[libvirt] [PATCH] node: Don't return invalid pointers



Commit 4337bc57be introduced code that would in certain error paths
unref the last reference of a pointer, but return it.

Clear the pointers before returning them
---
 src/node_device/node_device_driver.c | 8 ++++++--
 src/test/test_driver.c               | 4 +++-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index ba3da6288..3a6eeaaae 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -241,8 +241,10 @@ nodeDeviceLookupByName(virConnectPtr conn, const char *name)
         goto cleanup;

     if ((ret = virGetNodeDevice(conn, name))) {
-        if (VIR_STRDUP(ret->parent, obj->def->parent) < 0)
+        if (VIR_STRDUP(ret->parent, obj->def->parent) < 0) {
             virObjectUnref(ret);
+            ret = NULL;
+        }
     }

  cleanup:
@@ -285,8 +287,10 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
                             goto out;

                         if ((dev = virGetNodeDevice(conn, obj->def->name))) {
-                            if (VIR_STRDUP(dev->parent, obj->def->parent) < 0)
+                            if (VIR_STRDUP(dev->parent, obj->def->parent) < 0) {
                                 virObjectUnref(dev);
+                                dev = NULL;
+                            }
                         }
                         virNodeDeviceObjUnlock(obj);
                         goto out;
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 2db3f7ddf..9330d9ea6 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -5331,8 +5331,10 @@ testNodeDeviceLookupByName(virConnectPtr conn, const char *name)
         goto cleanup;

     if ((ret = virGetNodeDevice(conn, name))) {
-        if (VIR_STRDUP(ret->parent, obj->def->parent) < 0)
+        if (VIR_STRDUP(ret->parent, obj->def->parent) < 0) {
             virObjectUnref(ret);
+            ret = NULL;
+        }
     }

  cleanup:
-- 
2.12.2


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