From patchwork Wed Sep 28 14:44:30 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 116819 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 700B61007D1 for ; Thu, 29 Sep 2011 01:18:24 +1000 (EST) Received: from localhost ([::1]:51006 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8vOz-0005d1-Vt for incoming@patchwork.ozlabs.org; Wed, 28 Sep 2011 10:46:25 -0400 Received: from eggs.gnu.org ([140.186.70.92]:46933) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8vO1-0003Ap-6x for qemu-devel@nongnu.org; Wed, 28 Sep 2011 10:45:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R8vNz-0004zR-8O for qemu-devel@nongnu.org; Wed, 28 Sep 2011 10:45:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46813) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8vNy-0004zD-O2 for qemu-devel@nongnu.org; Wed, 28 Sep 2011 10:45:23 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p8SEj0Hd016476 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 28 Sep 2011 10:45:00 -0400 Received: from localhost (ovpn-113-147.phx2.redhat.com [10.3.113.147]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p8SEiwv9027281; Wed, 28 Sep 2011 10:44:59 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 28 Sep 2011 11:44:30 -0300 Message-Id: <1317221085-5825-7-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1317221085-5825-1-git-send-email-lcapitulino@redhat.com> References: <1317221085-5825-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, aliguori@us.ibm.com, mdroth@linux.vnet.ibm.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 06/21] qapi: dealloc visitor, fix premature free and iteration logic 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: Michael Roth Currently we do 3 things wrong: 1) The list iterator, in practice, is used in a manner where the pointer we pass in is the same as the pointer we assign the output to from visit_next_list(). This causes an infinite loop where we keep freeing the same structures. 2) We attempt to free list->value rather than list. visit_type_ handles this. We should only be concerned with the containing list. 3) We free prematurely: iterator function will continue accessing values we've already freed. This patch should fix all of these issues. QmpOutputVisitor also suffers from 1). Signed-off-by: Michael Roth Signed-off-by: Luiz Capitulino Reviewed-by: Anthony Liguori --- qapi/qapi-dealloc-visitor.c | 20 +++++++++++++++----- 1 files changed, 15 insertions(+), 5 deletions(-) diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c index f629061..6b586ad 100644 --- a/qapi/qapi-dealloc-visitor.c +++ b/qapi/qapi-dealloc-visitor.c @@ -26,6 +26,7 @@ struct QapiDeallocVisitor { Visitor visitor; QTAILQ_HEAD(, StackEntry) stack; + bool is_list_head; }; static QapiDeallocVisitor *to_qov(Visitor *v) @@ -70,15 +71,24 @@ static void qapi_dealloc_end_struct(Visitor *v, Error **errp) static void qapi_dealloc_start_list(Visitor *v, const char *name, Error **errp) { + QapiDeallocVisitor *qov = to_qov(v); + qov->is_list_head = true; } -static GenericList *qapi_dealloc_next_list(Visitor *v, GenericList **list, +static GenericList *qapi_dealloc_next_list(Visitor *v, GenericList **listp, Error **errp) { - GenericList *retval = *list; - g_free(retval->value); - *list = retval->next; - return retval; + GenericList *list = *listp; + QapiDeallocVisitor *qov = to_qov(v); + + if (!qov->is_list_head) { + *listp = list->next; + g_free(list); + return *listp; + } + + qov->is_list_head = false; + return list; } static void qapi_dealloc_end_list(Visitor *v, Error **errp)