All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxim Levitsky <mlevitsk@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	qemu-block@nongnu.org, "Max Reitz" <mreitz@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Maxim Levitsky" <mlevitsk@redhat.com>
Subject: [PATCH 3/4] libqtest: fix memory leak in the qtest_qmp_event_ref
Date: Mon, 19 Oct 2020 19:37:01 +0300	[thread overview]
Message-ID: <20201019163702.471239-4-mlevitsk@redhat.com> (raw)
In-Reply-To: <20201019163702.471239-1-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>
---
 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 bd96cb6fdd..9ae052d566 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.26.2



  parent reply	other threads:[~2020-10-19 16:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-19 16:36 [PATCH 0/4] Assorted fixes to tests that were broken by recent scsi changes Maxim Levitsky
2020-10-19 16:36 ` [PATCH 1/4] qdev: Fix two typos Maxim Levitsky
2020-10-19 19:51   ` Philippe Mathieu-Daudé
2020-10-24  5:34   ` Thomas Huth
2020-10-26 19:34     ` Laurent Vivier
2020-10-19 16:37 ` [PATCH 2/4] libqtest: fix the order of buffered events Maxim Levitsky
2020-10-19 16:37 ` Maxim Levitsky [this message]
2020-10-24  5:37   ` [PATCH 3/4] libqtest: fix memory leak in the qtest_qmp_event_ref Thomas Huth
2020-10-19 16:37 ` [PATCH 4/4] iotests: rewrite iotest 240 in python Maxim Levitsky
2020-10-29 11:16   ` Christian Borntraeger
2020-10-29 12:32     ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201019163702.471239-4-mlevitsk@redhat.com \
    --to=mlevitsk@redhat.com \
    --cc=berrange@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.