[PATCH 01/12] Add explicit non-NULL check for virObjectUnlock()

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

 



A lot of users of virObjectUnlock() use it this way:

if (obj)
   virObjectUnlock(obj);

And while passing NULL is not harmless, it generates a warning like

virObjectUnlock:340 : Object 0x0 ((unknown)) is not a virObjectLockable instance

To make this function usage simplier, check if argument is not NULL
before calling virObjectIsClass() and allow caller not to care about
that.
---
 src/util/virobject.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/util/virobject.c b/src/util/virobject.c
index 6cb84b4..19e1268 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -335,6 +335,9 @@ void virObjectUnlock(void *anyobj)
 {
     virObjectLockablePtr obj = anyobj;
 
+    if (!obj)
+        return;
+
     if (!virObjectIsClass(obj, virObjectLockableClass)) {
         VIR_WARN("Object %p (%s) is not a virObjectLockable instance",
                  obj, obj ? obj->parent.klass->name : "(unknown)");
-- 
1.9.0

--
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]