From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:38714) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uap1y-0002Cf-Vw for qemu-devel@nongnu.org; Fri, 10 May 2013 11:14:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uap1x-0004PZ-OK for qemu-devel@nongnu.org; Fri, 10 May 2013 11:14:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50292) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uap1x-0004PQ-Gy for qemu-devel@nongnu.org; Fri, 10 May 2013 11:14:45 -0400 Date: Fri, 10 May 2013 11:14:20 -0400 From: Luiz Capitulino Message-ID: <20130510111420.5e19c89c@redhat.com> In-Reply-To: <1368152462-13219-6-git-send-email-mdroth@linux.vnet.ibm.com> References: <1368152462-13219-1-git-send-email-mdroth@linux.vnet.ibm.com> <1368152462-13219-6-git-send-email-mdroth@linux.vnet.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 05/10] qapi: fix leak in unit tests List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Michael Roth Cc: akong@redhat.com, lersek@redhat.com, qemu-devel@nongnu.org On Thu, 9 May 2013 21:20:57 -0500 Michael Roth wrote: > qmp_output_get_qobject() increments the qobject's reference count. Since > we currently pass this straight into qobject_to_json() so we can feed > the data into a QMP input visitor, we never actually free the underlying > qobject when qmp_output_visitor_cleanup() is called. This causes leaks > on all of the QMP serialization tests. > > Fix this by holding a pointer to the qobject and decref'ing it before > returning from qmp_deserialize(). > > Signed-off-by: Michael Roth I've cherry-picked this one into the qmp branch for 1.5. > --- > tests/test-visitor-serialization.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serialization.c > index e84926f..8c8adac 100644 > --- a/tests/test-visitor-serialization.c > +++ b/tests/test-visitor-serialization.c > @@ -657,11 +657,16 @@ static void qmp_deserialize(void **native_out, void *datap, > VisitorFunc visit, Error **errp) > { > QmpSerializeData *d = datap; > - QString *output_json = qobject_to_json(qmp_output_get_qobject(d->qov)); > - QObject *obj = qobject_from_json(qstring_get_str(output_json)); > + QString *output_json; > + QObject *obj_orig, *obj; > + > + obj_orig = qmp_output_get_qobject(d->qov); > + output_json = qobject_to_json(obj_orig); > + obj = qobject_from_json(qstring_get_str(output_json)); > > QDECREF(output_json); > d->qiv = qmp_input_visitor_new(obj); > + qobject_decref(obj_orig); > qobject_decref(obj); > visit(qmp_input_get_visitor(d->qiv), native_out, errp); > }