[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 08/31] libqtest: fix memory leak in the qtest_qmp_event_ref
From: |
Thomas Huth |
Subject: |
[PULL 08/31] libqtest: fix memory leak in the qtest_qmp_event_ref |
Date: |
Mon, 26 Oct 2020 11:06:09 +0100 |
From: Maxim Levitsky <mlevitsk@redhat.com>
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>
---
tests/qtest/libqtest.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 0e304bdbd1..99deff47ef 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;
--
2.18.2
- [PULL 00/31] qtests and gitlab-CI/acceptance patches, Thomas Huth, 2020/10/26
- [PULL 01/31] tests/migration: fix memleak in wait_command/wait_command_fd, Thomas Huth, 2020/10/26
- [PULL 03/31] accel: Remove _WIN32 ifdef from qtest-cpus.c, Thomas Huth, 2020/10/26
- [PULL 02/31] tests/qtest/libqtest: Fix detection of architecture for binaries without path, Thomas Huth, 2020/10/26
- [PULL 04/31] accel: move qtest CpusAccel functions to a common location, Thomas Huth, 2020/10/26
- [PULL 05/31] accel: Add xen CpusAccel using dummy-cpus, Thomas Huth, 2020/10/26
- [PULL 06/31] tests/qtest: Make npcm7xx_timer-test conditional on CONFIG_NPCM7XX, Thomas Huth, 2020/10/26
- [PULL 07/31] libqtest: fix the order of buffered events, Thomas Huth, 2020/10/26
- [PULL 08/31] libqtest: fix memory leak in the qtest_qmp_event_ref,
Thomas Huth <=
- [PULL 09/31] memory: Add FlatView foreach function, Thomas Huth, 2020/10/26
- [PULL 10/31] fuzz: Add generic virtual-device fuzzer, Thomas Huth, 2020/10/26
- [PULL 11/31] fuzz: Add PCI features to the generic fuzzer, Thomas Huth, 2020/10/26
- [PULL 12/31] fuzz: Add DMA support to the generic-fuzzer, Thomas Huth, 2020/10/26
- [PULL 15/31] fuzz: Add support for custom crossover functions, Thomas Huth, 2020/10/26
- [PULL 14/31] fuzz: Add fuzzer callbacks to DMA-read functions, Thomas Huth, 2020/10/26
- [PULL 19/31] scripts/oss-fuzz: Add crash trace minimization script, Thomas Huth, 2020/10/26
- [PULL 16/31] fuzz: add a DISABLE_PCI op to generic-fuzzer, Thomas Huth, 2020/10/26
- [PULL 20/31] fuzz: Add instructions for using generic-fuzz, Thomas Huth, 2020/10/26
- [PULL 21/31] fuzz: add an "opaque" to the FuzzTarget struct, Thomas Huth, 2020/10/26