aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Crosthwaite <peter.crosthwaite@xilinx.com>2014-06-05 23:13:36 -0700
committerPaolo Bonzini <pbonzini@redhat.com>2014-07-01 10:20:41 +0200
commit8ffad850ef5ae14287d0e185d478c9a35820482c (patch)
tree6d3f53dde07032ba978b4d05d59edc7a1e6e7bbe
parentc28322d10cd5f0529605b48684d2b82c9eb9c020 (diff)
downloadqemu-arm-8ffad850ef5ae14287d0e185d478c9a35820482c.tar.gz
qom: object: Ignore refs/unrefs of NULL
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 <peter.crosthwaite@xilinx.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--qom/object.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/qom/object.c b/qom/object.c
index d5de8f6062..0e8267bc2a 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -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)