]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Add object checking for virObject{Ref|Unref}
authorJohn Ferlan <jferlan@redhat.com>
Fri, 31 Mar 2017 15:35:05 +0000 (11:35 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 15 Aug 2017 01:41:59 +0000 (21:41 -0400)
Rather than assuming that what's passed to virObject{Ref|Unref}
would be a virObjectPtr as long as it's not NULL, let's do the
similar checks virObjectIsClass in order to prevent a possible
increment or decrement to some field at the obj->u.s.refs offset.

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/util/virobject.c

index 54d78b00181fcfa4fa46909ac31847decb02d00b..cfa821c4b0be7f8a1513e35ee65ceaf39f36b48d 100644 (file)
@@ -343,7 +343,7 @@ virObjectUnref(void *anyobj)
 {
     virObjectPtr obj = anyobj;
 
-    if (!obj)
+    if (VIR_OBJECT_NOTVALID(obj))
         return false;
 
     bool lastRef = virAtomicIntDecAndTest(&obj->u.s.refs);
@@ -382,7 +382,7 @@ virObjectRef(void *anyobj)
 {
     virObjectPtr obj = anyobj;
 
-    if (!obj)
+    if (VIR_OBJECT_NOTVALID(obj))
         return NULL;
     virAtomicIntInc(&obj->u.s.refs);
     PROBE(OBJECT_REF, "obj=%p", obj);