From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:42542) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0FwM-00025l-Fy for qemu-devel@nongnu.org; Wed, 22 Feb 2012 12:25:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S0FwH-000271-0T for qemu-devel@nongnu.org; Wed, 22 Feb 2012 12:25:18 -0500 Received: from relay1.mentorg.com ([192.94.38.131]:37643) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0FwG-00026x-Qx for qemu-devel@nongnu.org; Wed, 22 Feb 2012 12:25:12 -0500 Message-ID: <4F452511.40501@mentor.com> Date: Wed, 22 Feb 2012 19:25:37 +0200 From: Alexander Barabash MIME-Version: 1.0 References: <1329931346-28207-1-git-send-email-alexander_barabash@mentor.com> <4F4524B3.7020500@redhat.com> In-Reply-To: <4F4524B3.7020500@redhat.com> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] qom: In function object_set_link_property(), first call object_ref(), then object_unref(). List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org On 02/22/2012 07:24 PM, Paolo Bonzini wrote: > On 02/22/2012 06:22 PM, alexander_barabash@mentor.com wrote: >> 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 >> --- >> 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, > Reviewed-by: Paolo Bonzini Sorry, I did not figure out yet how to add the "v2" to the subject line. )) Alex