From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48092) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzmHO-00040K-JK for qemu-devel@nongnu.org; Wed, 25 Jun 2014 08:26:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WzmHI-0001Hp-L8 for qemu-devel@nongnu.org; Wed, 25 Jun 2014 08:26:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53316) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzmHI-0001Hh-Ds for qemu-devel@nongnu.org; Wed, 25 Jun 2014 08:26:16 -0400 From: Paolo Bonzini Date: Wed, 25 Jun 2014 14:25:50 +0200 Message-Id: <1403699158-4344-7-git-send-email-pbonzini@redhat.com> In-Reply-To: <1403699158-4344-1-git-send-email-pbonzini@redhat.com> References: <1403699158-4344-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH for 2.1 06/14] qom: object: Ignore refs/unrefs of NULL List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Crosthwaite From: Peter Crosthwaite 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 Signed-off-by: Paolo Bonzini --- qom/object.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/qom/object.c b/qom/object.c index a3b8cf3..31bf8b9 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) -- 1.8.3.1