Received: from eggs.gnu.org ([2001:4830:134:3::10]:48650) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WuhVO-000854-6H for qemu-devel@nongnu.org; Wed, 11 Jun 2014 08:19:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WuhVI-0001QD-6u for qemu-devel@nongnu.org; Wed, 11 Jun 2014 08:19:50 -0400 Received: from mail-wi0-x233.google.com ([2a00:1450:400c:c05::233]:41706) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WuhVH-0001Q2-W3 for qemu-devel@nongnu.org; Wed, 11 Jun 2014 08:19:44 -0400 Received: by mail-wi0-f179.google.com with SMTP id cc10so994313wib.6 for ; Wed, 11 Jun 2014 05:19:43 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 11 Jun 2014 14:19:24 +0200 Message-Id: <1402489176-19738-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1402489176-19738-1-git-send-email-pbonzini@redhat.com> References: <1402489176-19738-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [RFC PATCH 01/13] 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@xilinx.com, afaerber@suse.de 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 e146ae5..3650a5b 100644 --- a/qom/object.c +++ b/qom/object.c @@ -709,11 +709,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 */ @@ -1132,13 +1138,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