From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:39317) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UaDtl-0007j9-I1 for qemu-devel@nongnu.org; Wed, 08 May 2013 19:35:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UaDtk-00071j-Jh for qemu-devel@nongnu.org; Wed, 08 May 2013 19:35:49 -0400 Received: from mail-ie0-x22f.google.com ([2607:f8b0:4001:c03::22f]:37343) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UaDtk-00071e-BR for qemu-devel@nongnu.org; Wed, 08 May 2013 19:35:48 -0400 Received: by mail-ie0-f175.google.com with SMTP id s9so4315147iec.20 for ; Wed, 08 May 2013 16:35:48 -0700 (PDT) Sender: fluxion From: Michael Roth Date: Wed, 8 May 2013 18:33:54 -0500 Message-Id: <1368056037-16350-6-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1368056037-16350-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1368056037-16350-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 5/8] qapi: fix leak in unit tests List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: akong@redhat.com, lcapitulino@redhat.com 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 --- 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); } -- 1.7.9.5