From patchwork Wed Feb 22 17:22:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Barabash X-Patchwork-Id: 142512 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BF880B6FAB for ; Thu, 23 Feb 2012 04:22:22 +1100 (EST) Received: from localhost ([::1]:49075 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0FtU-0000Fq-5q for incoming@patchwork.ozlabs.org; Wed, 22 Feb 2012 12:22:20 -0500 Received: from eggs.gnu.org ([140.186.70.92]:46246) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0FtK-0000FZ-HV for qemu-devel@nongnu.org; Wed, 22 Feb 2012 12:22:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S0FtE-0001Iu-TH for qemu-devel@nongnu.org; Wed, 22 Feb 2012 12:22:10 -0500 Received: from relay1.mentorg.com ([192.94.38.131]:37189) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0FtE-0001Iq-Ot for qemu-devel@nongnu.org; Wed, 22 Feb 2012 12:22:04 -0500 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1S0FtD-0005Ns-SU from Alexander_Barabash@mentor.com ; Wed, 22 Feb 2012 09:22:03 -0800 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Wed, 22 Feb 2012 09:22:03 -0800 Received: from silver.isr.mentorg.com (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.1.289.1; Wed, 22 Feb 2012 17:22:01 +0000 From: To: Date: Wed, 22 Feb 2012 19:22:26 +0200 Message-ID: <1329931346-28207-1-git-send-email-alexander_barabash@mentor.com> X-Mailer: git-send-email 1.7.5.4 MIME-Version: 1.0 X-OriginalArrivalTime: 22 Feb 2012 17:22:03.0714 (UTC) FILETIME=[7E802220:01CCF186] X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-Received-From: 192.94.38.131 Cc: pbonzini@redhat.com, Alexander Barabash Subject: [Qemu-devel] [PATCH] qom: In function object_set_link_property(), first call object_ref(), then object_unref(). X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Alexander Barabash In the old implementation, if the new value of the property links to the same object, as the old value, that object is first unref-ed, and then ref-ed. This leads to unintended deinitialization of that object. In the new implementation, this is fixed. Signed-off-by: Alexander Barabash Reviewed-by: Paolo Bonzini --- qom/object.c | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-) diff --git a/qom/object.c b/qom/object.c index 941c291..e6591e1 100644 --- a/qom/object.c +++ b/qom/object.c @@ -892,6 +892,7 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque, const char *name, Error **errp) { Object **child = opaque; + Object *old_target; bool ambiguous = false; const char *type; char *path; @@ -901,10 +902,8 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque, visit_type_str(v, &path, name, errp); - if (*child) { - object_unref(*child); - *child = NULL; - } + old_target = *child; + *child = NULL; if (strcmp(path, "") != 0) { Object *target; @@ -930,6 +929,10 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque, } g_free(path); + + if (old_target != NULL) { + object_unref(old_target); + } } void object_property_add_link(Object *obj, const char *name,