From patchwork Tue Mar 27 12:20:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 148943 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AEAD4B6EEA for ; Wed, 28 Mar 2012 00:23:15 +1100 (EST) Received: from localhost ([::1]:35259 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCVP5-0002aX-VC for incoming@patchwork.ozlabs.org; Tue, 27 Mar 2012 08:21:35 -0400 Received: from eggs.gnu.org ([208.118.235.92]:50101) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCVOQ-0000sC-NC for qemu-devel@nongnu.org; Tue, 27 Mar 2012 08:21:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SCVOK-0000IC-AE for qemu-devel@nongnu.org; Tue, 27 Mar 2012 08:20:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:7898) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCVOK-0000Hn-27 for qemu-devel@nongnu.org; Tue, 27 Mar 2012 08:20:48 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q2RCKkJV025233 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 27 Mar 2012 08:20:46 -0400 Received: from localhost (ovpn-113-71.phx2.redhat.com [10.3.113.71]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q2RCKjGM025605; Tue, 27 Mar 2012 08:20:46 -0400 From: Luiz Capitulino To: aliguori@us.ibm.com Date: Tue, 27 Mar 2012 09:20:39 -0300 Message-Id: <1332850851-4059-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1332850851-4059-1-git-send-email-lcapitulino@redhat.com> References: <1332850851-4059-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Laszlo Ersek , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 01/13] qapi: fix double free in qmp_output_visitor_cleanup() 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: Laszlo Ersek Stack entries in QmpOutputVisitor are navigation links (weak references), except the bottom (ie. least recently added) entry, which owns the root QObject [1]. Make qmp_output_visitor_cleanup() drop the stack entries, then release the QObject tree by the root. Attempting to serialize an invalid enum inside a dictionary is an example for triggering the double free. [1] http://lists.nongnu.org/archive/html/qemu-devel/2012-03/msg03276.html Signed-off-by: Laszlo Ersek Signed-off-by: Luiz Capitulino --- qapi/qmp-output-visitor.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c index e0697b0..2bce9d5 100644 --- a/qapi/qmp-output-visitor.c +++ b/qapi/qmp-output-visitor.c @@ -199,14 +199,16 @@ void qmp_output_visitor_cleanup(QmpOutputVisitor *v) { QStackEntry *e, *tmp; + /* The bottom QStackEntry, if any, owns the root QObject. See the + * qmp_output_push_obj() invocations in qmp_output_add_obj(). */ + QObject *root = QTAILQ_EMPTY(&v->stack) ? NULL : qmp_output_first(v); + QTAILQ_FOREACH_SAFE(e, &v->stack, node, tmp) { QTAILQ_REMOVE(&v->stack, e, node); - if (e->value) { - qobject_decref(e->value); - } g_free(e); } + qobject_decref(root); g_free(v); }