All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, eblake@redhat.com, armbru@redhat.com,
	pbonzini@redhat.com,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PULLv2 23/25] tests: pc-cpu-test leaks fixes
Date: Thu,  8 Sep 2016 18:17:18 +0400	[thread overview]
Message-ID: <20160908141720.30641-24-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20160908141720.30641-1-marcandre.lureau@redhat.com>

The path is allocated and should be freed.

The qmp response should be unref, but then 'machine' must be duplicated.

Use a destroy function for the PCTestData.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 tests/pc-cpu-test.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/tests/pc-cpu-test.c b/tests/pc-cpu-test.c
index 4428cea..c3a2633 100644
--- a/tests/pc-cpu-test.c
+++ b/tests/pc-cpu-test.c
@@ -14,7 +14,7 @@
 #include "qapi/qmp/types.h"
 
 struct PCTestData {
-    const char *machine;
+    char *machine;
     const char *cpu_model;
     unsigned sockets;
     unsigned cores;
@@ -71,6 +71,14 @@ static void test_pc_without_cpu_add(gconstpointer data)
     g_free(args);
 }
 
+static void test_data_free(gpointer data)
+{
+    PCTestData *pc = data;
+
+    g_free(pc->machine);
+    g_free(pc);
+}
+
 static void add_pc_test_cases(void)
 {
     QDict *response, *minfo;
@@ -78,7 +86,8 @@ static void add_pc_test_cases(void)
     const QListEntry *p;
     QObject *qobj;
     QString *qstr;
-    const char *mname, *path;
+    const char *mname;
+    char *path;
     PCTestData *data;
 
     qtest_start("-machine none");
@@ -99,7 +108,7 @@ static void add_pc_test_cases(void)
             continue;
         }
         data = g_malloc(sizeof(PCTestData));
-        data->machine = mname;
+        data->machine = g_strdup(mname);
         data->cpu_model = "Haswell"; /* 1.3+ theoretically */
         data->sockets = 1;
         data->cores = 3;
@@ -119,14 +128,19 @@ static void add_pc_test_cases(void)
             path = g_strdup_printf("cpu/%s/init/%ux%ux%u&maxcpus=%u",
                                    mname, data->sockets, data->cores,
                                    data->threads, data->maxcpus);
-            qtest_add_data_func(path, data, test_pc_without_cpu_add);
+            qtest_add_data_func_full(path, data, test_pc_without_cpu_add,
+                                     test_data_free);
+            g_free(path);
         } else {
             path = g_strdup_printf("cpu/%s/add/%ux%ux%u&maxcpus=%u",
                                    mname, data->sockets, data->cores,
                                    data->threads, data->maxcpus);
-            qtest_add_data_func(path, data, test_pc_with_cpu_add);
+            qtest_add_data_func_full(path, data, test_pc_with_cpu_add,
+                                     test_data_free);
+            g_free(path);
         }
     }
+    QDECREF(response);
     qtest_end();
 }
 
-- 
2.10.0

  parent reply	other threads:[~2016-09-08 14:18 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-08 14:16 [Qemu-devel] [PULLv2 00/25] Leak patches Marc-André Lureau
2016-09-08 14:16 ` [Qemu-devel] [PULLv2 01/25] tests: fix test-qga leaks Marc-André Lureau
2016-09-08 14:16 ` [Qemu-devel] [PULLv2 02/25] glib-compat: add g_(s)list_free_full() Marc-André Lureau
2016-09-08 14:16 ` [Qemu-devel] [PULLv2 03/25] qga: free the whole blacklist Marc-André Lureau
2016-09-08 14:16 ` [Qemu-devel] [PULLv2 04/25] qga: free remaining leaking state Marc-André Lureau
2016-09-08 14:17 ` [Qemu-devel] [PULLv2 05/25] tests: fix test-cutils leaks Marc-André Lureau
2016-09-08 14:17 ` [Qemu-devel] [PULLv2 06/25] tests: fix test-vmstate leaks Marc-André Lureau
2016-09-08 14:17 ` [Qemu-devel] [PULLv2 07/25] tests: fix test-iov leaks Marc-André Lureau
2016-09-08 14:17 ` [Qemu-devel] [PULLv2 08/25] tests: fix check-qom-interface leaks Marc-André Lureau
2016-09-08 14:17 ` [Qemu-devel] [PULLv2 09/25] tests: fix check-qom-proplist leaks Marc-André Lureau
2016-09-08 14:17 ` [Qemu-devel] [PULLv2 10/25] tests: fix leak in test-string-input-visitor Marc-André Lureau
2016-09-08 14:17 ` [Qemu-devel] [PULLv2 11/25] portio: keep references on portio Marc-André Lureau
2016-09-08 14:17 ` [Qemu-devel] [PULLv2 12/25] pc: simplify passing qemu_irq Marc-André Lureau
2016-09-08 14:17 ` [Qemu-devel] [PULLv2 13/25] pc: don't leak a20_line Marc-André Lureau
2016-09-08 14:17 ` [Qemu-devel] [PULLv2 14/25] machine: use class base init generated name Marc-André Lureau
2016-09-08 14:17 ` [Qemu-devel] [PULLv2 15/25] acpi-build: fix array leak Marc-André Lureau
2016-09-08 14:17 ` [Qemu-devel] [PULLv2 16/25] tests: fix qom-test leaks Marc-André Lureau
2016-09-08 14:17 ` [Qemu-devel] [PULLv2 17/25] pc: free i8259 Marc-André Lureau
2016-09-08 14:17 ` [Qemu-devel] [PULLv2 18/25] pc: keep gsi reference Marc-André Lureau
2016-09-08 14:17 ` [Qemu-devel] [PULLv2 19/25] sd: free timer Marc-André Lureau
2016-09-08 14:17 ` [Qemu-devel] [PULLv2 20/25] ipmi: free extern timer Marc-André Lureau
2016-09-08 14:17 ` [Qemu-devel] [PULLv2 21/25] bus: simplify name handling Marc-André Lureau
2016-09-08 14:17 ` [Qemu-devel] [PULLv2 22/25] tests: add qtest_add_data_func_full Marc-André Lureau
2016-09-08 14:17 ` Marc-André Lureau [this message]
2016-09-08 14:17 ` [Qemu-devel] [PULLv2 24/25] tests: fix rsp leak in postcopy-test Marc-André Lureau
2016-09-08 14:17 ` [Qemu-devel] [PULLv2 25/25] tests: fix postcopy-test leaks Marc-André Lureau
2016-09-09 10:07 ` [Qemu-devel] [PULLv2 00/25] Leak patches Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160908141720.30641-24-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.