[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH for-2.7 v4 33/36] tests: pc-cpu-test leaks fixes
From: |
marcandre . lureau |
Subject: |
[Qemu-devel] [PATCH for-2.7 v4 33/36] tests: pc-cpu-test leaks fixes |
Date: |
Fri, 5 Aug 2016 12:24:18 +0400 |
From: Marc-André Lureau <address@hidden>
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 <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
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.9.0
- [Qemu-devel] [PATCH for-2.7 v4 24/36] ahci: free irqs array, (continued)
- [Qemu-devel] [PATCH for-2.7 v4 24/36] ahci: free irqs array, marcandre . lureau, 2016/08/05
- [Qemu-devel] [PATCH for-2.7 v4 25/36] sd: free timer, marcandre . lureau, 2016/08/05
- [Qemu-devel] [PATCH for-2.7 v4 26/36] qjson: free str, marcandre . lureau, 2016/08/05
- [Qemu-devel] [PATCH for-2.7 v4 27/36] virtio-input: free config list, marcandre . lureau, 2016/08/05
- [Qemu-devel] [PATCH for-2.7 v4 28/36] ipmi: free extern timer, marcandre . lureau, 2016/08/05
- [Qemu-devel] [PATCH for-2.7 v4 29/36] usb: free USBDevice.strings, marcandre . lureau, 2016/08/05
- [Qemu-devel] [PATCH for-2.7 v4 30/36] usb: free leaking path, marcandre . lureau, 2016/08/05
- [Qemu-devel] [PATCH for-2.7 v4 31/36] bus: simplify name handling, marcandre . lureau, 2016/08/05
- [Qemu-devel] [PATCH for-2.7 v4 32/36] tests: add qtest_add_data_func_full, marcandre . lureau, 2016/08/05
- [Qemu-devel] [PATCH for-2.7 v4 33/36] tests: pc-cpu-test leaks fixes,
marcandre . lureau <=
- [Qemu-devel] [PATCH for-2.7 v4 34/36] tests: fix rsp leak in postcopy-test, marcandre . lureau, 2016/08/05
- [Qemu-devel] [PATCH for-2.7 v4 35/36] ahci: fix sglist leak on retry, marcandre . lureau, 2016/08/05
- [Qemu-devel] [PATCH for-2.7 v4 36/36] tests: fix postcopy-test leaks, marcandre . lureau, 2016/08/05
- Re: [Qemu-devel] [PATCH for-2.7 v4 00/36] Various memory leak fixes, Daniel P. Berrange, 2016/08/05
- Re: [Qemu-devel] [PATCH for-2.7 v4 00/36] Various memory leak fixes, Marc-André Lureau, 2016/08/05