* [Qemu-devel] [PATCH] qom-test: fix qmp() leaks
@ 2015-11-26 15:31 marcandre.lureau
2015-12-02 18:50 ` Markus Armbruster
0 siblings, 1 reply; 2+ messages in thread
From: marcandre.lureau @ 2015-11-26 15:31 UTC (permalink / raw)
To: qemu-devel; +Cc: Marc-André Lureau, armbru
From: Marc-André Lureau <marcandre.lureau@redhat.com>
Before this patch ASAN reported:
SUMMARY: AddressSanitizer: 677165875 byte(s) leaked in 1272437 allocation(s)
After this patch:
SUMMARY: AddressSanitizer: 465 byte(s) leaked in 32 allocation(s)
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
tests/qom-test.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/tests/qom-test.c b/tests/qom-test.c
index fde04e7..8a08fd7 100644
--- a/tests/qom-test.c
+++ b/tests/qom-test.c
@@ -47,7 +47,7 @@ static bool is_blacklisted(const char *arch, const char *mach)
static void test_properties(const char *path, bool recurse)
{
char *child_path;
- QDict *response, *tuple;
+ QDict *response, *tuple, *tmp;
QList *list;
QListEntry *entry;
@@ -57,6 +57,7 @@ static void test_properties(const char *path, bool recurse)
g_assert(response);
if (!recurse) {
+ QDECREF(response);
return;
}
@@ -75,19 +76,21 @@ static void test_properties(const char *path, bool recurse)
} else {
const char *prop = qdict_get_str(tuple, "name");
g_test_message("Testing property %s.%s", path, prop);
- response = qmp("{ 'execute': 'qom-get',"
- " 'arguments': { 'path': %s,"
- " 'property': %s } }",
- path, prop);
+ tmp = qmp("{ 'execute': 'qom-get',"
+ " 'arguments': { 'path': %s,"
+ " 'property': %s } }",
+ path, prop);
/* qom-get may fail but should not, e.g., segfault. */
- g_assert(response);
+ g_assert(tmp);
+ QDECREF(tmp);
}
}
+ QDECREF(response);
}
-static void test_machine(gconstpointer data)
+static void test_machine(gpointer data)
{
- const char *machine = data;
+ char *machine = data;
char *args;
QDict *response;
@@ -98,9 +101,11 @@ static void test_machine(gconstpointer data)
response = qmp("{ 'execute': 'quit' }");
g_assert(qdict_haskey(response, "return"));
+ QDECREF(response);
qtest_end();
g_free(args);
+ g_free(machine);
}
static void add_machine_test_cases(void)
@@ -129,10 +134,12 @@ static void add_machine_test_cases(void)
mname = qstring_get_str(qstr);
if (!is_blacklisted(arch, mname)) {
path = g_strdup_printf("qom/%s", mname);
- qtest_add_data_func(path, mname, test_machine);
+ qtest_add_data_func(path, g_strdup(mname), test_machine);
}
}
+
qtest_end();
+ QDECREF(response);
}
int main(int argc, char **argv)
--
2.5.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [Qemu-devel] [PATCH] qom-test: fix qmp() leaks
2015-11-26 15:31 [Qemu-devel] [PATCH] qom-test: fix qmp() leaks marcandre.lureau
@ 2015-12-02 18:50 ` Markus Armbruster
0 siblings, 0 replies; 2+ messages in thread
From: Markus Armbruster @ 2015-12-02 18:50 UTC (permalink / raw)
To: marcandre.lureau; +Cc: qemu-devel
marcandre.lureau@redhat.com writes:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> Before this patch ASAN reported:
> SUMMARY: AddressSanitizer: 677165875 byte(s) leaked in 1272437 allocation(s)
>
> After this patch:
> SUMMARY: AddressSanitizer: 465 byte(s) leaked in 32 allocation(s)
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> tests/qom-test.c | 25 ++++++++++++++++---------
> 1 file changed, 16 insertions(+), 9 deletions(-)
>
> diff --git a/tests/qom-test.c b/tests/qom-test.c
> index fde04e7..8a08fd7 100644
> --- a/tests/qom-test.c
> +++ b/tests/qom-test.c
> @@ -47,7 +47,7 @@ static bool is_blacklisted(const char *arch, const char *mach)
> static void test_properties(const char *path, bool recurse)
> {
> char *child_path;
> - QDict *response, *tuple;
> + QDict *response, *tuple, *tmp;
> QList *list;
> QListEntry *entry;
>
> @@ -57,6 +57,7 @@ static void test_properties(const char *path, bool recurse)
> g_assert(response);
>
> if (!recurse) {
> + QDECREF(response);
> return;
> }
>
> @@ -75,19 +76,21 @@ static void test_properties(const char *path, bool recurse)
> } else {
> const char *prop = qdict_get_str(tuple, "name");
> g_test_message("Testing property %s.%s", path, prop);
> - response = qmp("{ 'execute': 'qom-get',"
> - " 'arguments': { 'path': %s,"
> - " 'property': %s } }",
> - path, prop);
> + tmp = qmp("{ 'execute': 'qom-get',"
> + " 'arguments': { 'path': %s,"
> + " 'property': %s } }",
> + path, prop);
> /* qom-get may fail but should not, e.g., segfault. */
> - g_assert(response);
> + g_assert(tmp);
> + QDECREF(tmp);
> }
> }
> + QDECREF(response);
> }
>
> -static void test_machine(gconstpointer data)
> +static void test_machine(gpointer data)
> {
> - const char *machine = data;
> + char *machine = data;
> char *args;
> QDict *response;
>
Why drop const?
> @@ -98,9 +101,11 @@ static void test_machine(gconstpointer data)
>
> response = qmp("{ 'execute': 'quit' }");
> g_assert(qdict_haskey(response, "return"));
> + QDECREF(response);
>
> qtest_end();
> g_free(args);
> + g_free(machine);
Hmm, I guess so you can g_free() without a cast.
> }
>
> static void add_machine_test_cases(void)
> @@ -129,10 +134,12 @@ static void add_machine_test_cases(void)
> mname = qstring_get_str(qstr);
> if (!is_blacklisted(arch, mname)) {
> path = g_strdup_printf("qom/%s", mname);
> - qtest_add_data_func(path, mname, test_machine);
> + qtest_add_data_func(path, g_strdup(mname), test_machine);
I wonder why changing test_machine()'s type doesn't make the compiler
gripe here... argh!
void qtest_add_data_func(const char *str, const void *data, void (*fn));
void (*fn) is just a stupid way to write void *fn. Bye-bye
type-checking.
I'll post a patch fixing this.
> }
> }
> +
> qtest_end();
> + QDECREF(response);
> }
>
> int main(int argc, char **argv)
Reviewed-by: Markus Armbruster <armbru@redhat.com>
I intend to rebase this patch onto mine. Changes should be trivial,
though.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-12-02 18:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-26 15:31 [Qemu-devel] [PATCH] qom-test: fix qmp() leaks marcandre.lureau
2015-12-02 18:50 ` Markus Armbruster
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).