From patchwork Fri Apr 5 14:08:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 234144 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 4CC232C00A0 for ; Sat, 6 Apr 2013 01:09:42 +1100 (EST) Received: from localhost ([::1]:54456 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UO7Km-0007TN-C4 for incoming@patchwork.ozlabs.org; Fri, 05 Apr 2013 10:09:40 -0400 Received: from eggs.gnu.org ([208.118.235.92]:33611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UO7KA-0007Oo-JX for qemu-devel@nongnu.org; Fri, 05 Apr 2013 10:09:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UO7K3-0008GC-9T for qemu-devel@nongnu.org; Fri, 05 Apr 2013 10:09:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:22022) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UO7K3-0008Fw-1N for qemu-devel@nongnu.org; Fri, 05 Apr 2013 10:08:55 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r35E8roq028602 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 5 Apr 2013 10:08:53 -0400 Received: from localhost (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r35E8pdK022373; Fri, 5 Apr 2013 10:08:52 -0400 From: Stefan Hajnoczi To: Date: Fri, 5 Apr 2013 16:08:42 +0200 Message-Id: <1365170926-6361-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1365170926-6361-1-git-send-email-stefanha@redhat.com> References: <1365170926-6361-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori , Stefan Hajnoczi , Stefan Berger Subject: [Qemu-devel] [PATCH 1/5] test-visitor-serialization: Fix some memory leaks 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: Stefan Berger This patch fixes some of the memory leaks in test-visitor-serialization but not all of them. Signed-off-by: Stefan Berger Signed-off-by: Stefan Hajnoczi --- tests/test-visitor-serialization.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serialization.c index 3c6b8df..e84926f 100644 --- a/tests/test-visitor-serialization.c +++ b/tests/test-visitor-serialization.c @@ -258,6 +258,7 @@ static void test_primitives(gconstpointer opaque) 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 * floating math to test "equality", just compare the formatted values @@ -275,6 +276,7 @@ static void test_primitives(gconstpointer opaque) 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 **native_out, void *datap, 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 **native_out, void *datap, { 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 */