diff options
author | Maxim Levitsky <mlevitsk@redhat.com> | 2020-10-19 19:37:01 +0300 |
---|---|---|
committer | Thomas Huth <thuth@redhat.com> | 2020-10-24 07:36:53 +0200 |
commit | d232b87ec6e3a8a04db9b647f61a1e3a6855a58f (patch) | |
tree | 900e1bc191f4fb1700708a2731e923b2a935a487 | |
parent | 7f9d519c0d37b8af0b228a4ed49d33ea095e9eb7 (diff) | |
download | qemu-d232b87ec6e3a8a04db9b647f61a1e3a6855a58f.zip qemu-d232b87ec6e3a8a04db9b647f61a1e3a6855a58f.tar.gz qemu-d232b87ec6e3a8a04db9b647f61a1e3a6855a58f.tar.bz2 |
libqtest: fix memory leak in the qtest_qmp_event_ref
The g_list_remove_link doesn't free the link element,
opposed to what I thought.
Switch to g_list_delete_link that does free it.
Also refactor the code a bit.
Thanks for Max Reitz for helping me with this.
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Message-Id: <20201019163702.471239-4-mlevitsk@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
-rw-r--r-- | tests/qtest/libqtest.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 0e304bd..99deff4 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -795,15 +795,12 @@ void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...) QDict *qtest_qmp_event_ref(QTestState *s, const char *event) { - GList *next = NULL; - QDict *response; - - for (GList *it = s->pending_events; it != NULL; it = next) { + while (s->pending_events) { - next = it->next; - response = (QDict *)it->data; + GList *first = s->pending_events; + QDict *response = (QDict *)first->data; - s->pending_events = g_list_remove_link(s->pending_events, it); + s->pending_events = g_list_delete_link(s->pending_events, first); if (!strcmp(qdict_get_str(response, "event"), event)) { return response; |