]> Git Repo - qemu.git/commitdiff
qom: object: Ignore refs/unrefs of NULL
authorPeter Crosthwaite <[email protected]>
Fri, 6 Jun 2014 06:13:36 +0000 (23:13 -0700)
committerPaolo Bonzini <[email protected]>
Tue, 1 Jul 2014 08:20:41 +0000 (10:20 +0200)
Just do nothing if passed NULL for a ref or unref. This avoids
call sites that manage a combination of NULL or non-NULL pointers
having to add iffery around every ref and unref.

Signed-off-by: Peter Crosthwaite <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
qom/object.c

index d5de8f6062e90e17e13b3fa53d5c4a84ea1ea0e9..0e8267bc2acc9d4ecb31344cbfb649a405d866f2 100644 (file)
@@ -711,11 +711,17 @@ GSList *object_class_get_list(const char *implements_type,
 
 void object_ref(Object *obj)
 {
+    if (!obj) {
+        return;
+    }
      atomic_inc(&obj->ref);
 }
 
 void object_unref(Object *obj)
 {
+    if (!obj) {
+        return;
+    }
     g_assert(obj->ref > 0);
 
     /* parent always holds a reference to its children */
@@ -1160,13 +1166,9 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
         return;
     }
 
-    if (new_target) {
-        object_ref(new_target);
-    }
+    object_ref(new_target);
     *child = new_target;
-    if (old_target != NULL) {
-        object_unref(old_target);
-    }
+    object_unref(old_target);
 }
 
 static Object *object_resolve_link_property(Object *parent, void *opaque, const gchar *part)
This page took 0.028177 seconds and 4 git commands to generate.