From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:36412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9nAt-0006cc-0n for qemu-devel@nongnu.org; Mon, 19 Mar 2012 20:44:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S9nAp-0002Ja-Td for qemu-devel@nongnu.org; Mon, 19 Mar 2012 20:43:42 -0400 Received: from mail-gy0-f173.google.com ([209.85.160.173]:33872) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9nAp-0002J5-Md for qemu-devel@nongnu.org; Mon, 19 Mar 2012 20:43:39 -0400 Received: by ghrr14 with SMTP id r14so6939471ghr.4 for ; Mon, 19 Mar 2012 17:43:37 -0700 (PDT) Sender: fluxion Date: Mon, 19 Mar 2012 19:43:32 -0500 From: Michael Roth Message-ID: <20120320004332.GA25518@illuin> References: <20120316170056.GA24953@illuin> <1331925372-5429-1-git-send-email-lersek@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1331925372-5429-1-git-send-email-lersek@redhat.com> Subject: Re: [Qemu-devel] [PATCH] qmp_output_visitor_cleanup(): fix double free List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Laszlo Ersek Cc: pbonzini@redhat.com, jcody@redhat.com, aliguori@us.ibm.com, qemu-devel@nongnu.org, lcapitulino@redhat.com On Fri, Mar 16, 2012 at 08:16:12PM +0100, Laszlo Ersek wrote: > 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 Tested-by: Michael Roth Looks good. Did you or Paolo want to re-send that test case with a SoB? I have a test case that triggers this by manually calling error_set(), but I think yours is better. > --- > qapi/qmp-output-visitor.c | 8 +++++--- > 1 files 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); > } > > -- > 1.7.1 >