From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48186) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1tXL-0002KV-7a for qemu-devel@nongnu.org; Tue, 01 Jul 2014 04:35:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X1tXE-0000rq-Ni for qemu-devel@nongnu.org; Tue, 01 Jul 2014 04:35:35 -0400 Received: from mail-wg0-x229.google.com ([2a00:1450:400c:c00::229]:44927) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1tXE-0000rb-Ee for qemu-devel@nongnu.org; Tue, 01 Jul 2014 04:35:28 -0400 Received: by mail-wg0-f41.google.com with SMTP id a1so9046943wgh.0 for ; Tue, 01 Jul 2014 01:35:27 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Tue, 1 Jul 2014 10:34:56 +0200 Message-Id: <1404203705-15674-7-git-send-email-pbonzini@redhat.com> In-Reply-To: <1404203705-15674-1-git-send-email-pbonzini@redhat.com> References: <1404203705-15674-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 06/15] 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 d5de8f6..0e8267b 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