tests: pc-cpu-test leaks fixes

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>
This commit is contained in:
Marc-André Lureau 2016-07-18 14:56:51 +04:00
parent 822e36ca35
commit 34e46f604d
1 changed files with 19 additions and 5 deletions

View File

@ -14,7 +14,7 @@
#include "qapi/qmp/types.h" #include "qapi/qmp/types.h"
struct PCTestData { struct PCTestData {
const char *machine; char *machine;
const char *cpu_model; const char *cpu_model;
unsigned sockets; unsigned sockets;
unsigned cores; unsigned cores;
@ -71,6 +71,14 @@ static void test_pc_without_cpu_add(gconstpointer data)
g_free(args); 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) static void add_pc_test_cases(void)
{ {
QDict *response, *minfo; QDict *response, *minfo;
@ -78,7 +86,8 @@ static void add_pc_test_cases(void)
const QListEntry *p; const QListEntry *p;
QObject *qobj; QObject *qobj;
QString *qstr; QString *qstr;
const char *mname, *path; const char *mname;
char *path;
PCTestData *data; PCTestData *data;
qtest_start("-machine none"); qtest_start("-machine none");
@ -99,7 +108,7 @@ static void add_pc_test_cases(void)
continue; continue;
} }
data = g_malloc(sizeof(PCTestData)); data = g_malloc(sizeof(PCTestData));
data->machine = mname; data->machine = g_strdup(mname);
data->cpu_model = "Haswell"; /* 1.3+ theoretically */ data->cpu_model = "Haswell"; /* 1.3+ theoretically */
data->sockets = 1; data->sockets = 1;
data->cores = 3; 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", path = g_strdup_printf("cpu/%s/init/%ux%ux%u&maxcpus=%u",
mname, data->sockets, data->cores, mname, data->sockets, data->cores,
data->threads, data->maxcpus); 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 { } else {
path = g_strdup_printf("cpu/%s/add/%ux%ux%u&maxcpus=%u", path = g_strdup_printf("cpu/%s/add/%ux%ux%u&maxcpus=%u",
mname, data->sockets, data->cores, mname, data->sockets, data->cores,
data->threads, data->maxcpus); 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(); qtest_end();
} }