From patchwork Thu Mar 28 11:22:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 231981 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 DC34A2C00B6 for ; Thu, 28 Mar 2013 22:22:39 +1100 (EST) Received: from localhost ([::1]:55749 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ULAuk-0001lM-36 for incoming@patchwork.ozlabs.org; Thu, 28 Mar 2013 07:22:38 -0400 Received: from eggs.gnu.org ([208.118.235.92]:39431) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ULAuR-0001lG-6n for qemu-devel@nongnu.org; Thu, 28 Mar 2013 07:22:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ULAuP-0000A9-Ke for qemu-devel@nongnu.org; Thu, 28 Mar 2013 07:22:18 -0400 Received: from e8.ny.us.ibm.com ([32.97.182.138]:53281) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ULAuP-00009q-GS for qemu-devel@nongnu.org; Thu, 28 Mar 2013 07:22:17 -0400 Received: from /spool/local by e8.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 28 Mar 2013 07:22:15 -0400 Received: from d01dlp03.pok.ibm.com (9.56.250.168) by e8.ny.us.ibm.com (192.168.1.108) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 28 Mar 2013 07:22:13 -0400 Received: from d01relay05.pok.ibm.com (d01relay05.pok.ibm.com [9.56.227.237]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 0935FC9001E; Thu, 28 Mar 2013 07:22:13 -0400 (EDT) Received: from d01av05.pok.ibm.com (d01av05.pok.ibm.com [9.56.224.195]) by d01relay05.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2SBMD1T338648; Thu, 28 Mar 2013 07:22:13 -0400 Received: from d01av05.pok.ibm.com (loopback [127.0.0.1]) by d01av05.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2SBMC8X008648; Thu, 28 Mar 2013 07:22:12 -0400 Received: from [9.2.141.150] (k-d941e-10.watson.ibm.com [9.2.141.150]) by d01av05.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r2SBMCrc008645; Thu, 28 Mar 2013 07:22:12 -0400 Message-ID: <515427E4.70402@linux.vnet.ibm.com> Date: Thu, 28 Mar 2013 07:22:12 -0400 From: Stefan Berger User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120911 Thunderbird/15.0.1 MIME-Version: 1.0 To: Michael Roth , qemu-trivial@nongnu.org X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13032811-9360-0000-0000-000011827433 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 32.97.182.138 Cc: Stefan Hajnoczi , qemu-devel Subject: [Qemu-devel] [PATCH v2] Fix some memory leaks in test-visitor-serialization 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 This patch fixes some of the memory leaks in test-visitor-serialization but not all of them. Signed-off-by: Stefan Berger --- v1->v2: call qobject_decref(obj) earlier --- tests/test-visitor-serialization.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) * floating math to test "equality", just compare the formatted values @@ -275,6 +276,7 @@ static void test_primitives(gconstpointe ops->cleanup(serialize_data); g_free(args); + g_free(pt_copy); } static void test_struct(gconstpointer opaque) @@ -660,6 +662,7 @@ static void qmp_deserialize(void **nativ QDECREF(output_json); d->qiv = qmp_input_visitor_new(obj); + qobject_decref(obj); visit(qmp_input_get_visitor(d->qiv), native_out, errp); } @@ -668,9 +671,12 @@ static void qmp_cleanup(void *datap) QmpSerializeData *d = datap; qmp_output_visitor_cleanup(d->qov); qmp_input_visitor_cleanup(d->qiv); + + g_free(d); } typedef struct StringSerializeData { + char *string; StringOutputVisitor *sov; StringInputVisitor *siv; } StringSerializeData; @@ -690,15 +696,19 @@ static void string_deserialize(void **na { StringSerializeData *d = datap; - d->siv = string_input_visitor_new(string_output_get_string(d->sov)); + d->string = string_output_get_string(d->sov); + d->siv = string_input_visitor_new(d->string); visit(string_input_get_visitor(d->siv), native_out, errp); } static void string_cleanup(void *datap) { StringSerializeData *d = datap; + string_output_visitor_cleanup(d->sov); string_input_visitor_cleanup(d->siv); + g_free(d->string); + g_free(d); } /* visitor registration, test harness */ Index: qemu-git.pt/tests/test-visitor-serialization.c =================================================================== --- qemu-git.pt.orig/tests/test-visitor-serialization.c +++ qemu-git.pt/tests/test-visitor-serialization.c @@ -258,6 +258,7 @@ static void test_primitives(gconstpointe g_assert(pt_copy != NULL); if (pt->type == PTYPE_STRING) { g_assert_cmpstr(pt->value.string, ==, pt_copy->value.string); + g_free((char *)pt_copy->value.string); } else if (pt->type == PTYPE_NUMBER) { /* we serialize with %f for our reference visitors, so rather than fuzzy