From: "Daniel P. Berrangé" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Daniel P. Berrangé" <berrange@redhat.com>,
"Grant Millar | Cylo" <rid@cylo.io>,
"Marc-André Lureau" <marcandre.lureau@gmail.com>
Subject: [PATCH 1/2] io: move websock resource release to close method
Date: Tue, 30 Sep 2025 12:08:33 +0100 [thread overview]
Message-ID: <20250930110834.2551757-2-berrange@redhat.com> (raw)
In-Reply-To: <20250930110834.2551757-1-berrange@redhat.com>
The QIOChannelWebsock object releases all its resources in the
finalize callback. This is too late, as callers expect to be
able to call qio_channel_close() to fully close a channel and
release resources related to I/O. Only releasing the underlying
QIOChannel transport can be delayed until finalize.
Furthermore the close callback must be robust against being
called multiple times. Thus when moving the code we now clear
the GSource ID using g_clear_handle_id.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
io/channel-websock.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/io/channel-websock.c b/io/channel-websock.c
index 0a8c5c4712..56d53355d5 100644
--- a/io/channel-websock.c
+++ b/io/channel-websock.c
@@ -919,16 +919,7 @@ static void qio_channel_websock_finalize(Object *obj)
{
QIOChannelWebsock *ioc = QIO_CHANNEL_WEBSOCK(obj);
- buffer_free(&ioc->encinput);
- buffer_free(&ioc->encoutput);
- buffer_free(&ioc->rawinput);
object_unref(OBJECT(ioc->master));
- if (ioc->io_tag) {
- g_source_remove(ioc->io_tag);
- }
- if (ioc->io_err) {
- error_free(ioc->io_err);
- }
}
@@ -1218,6 +1209,15 @@ static int qio_channel_websock_close(QIOChannel *ioc,
QIOChannelWebsock *wioc = QIO_CHANNEL_WEBSOCK(ioc);
trace_qio_channel_websock_close(ioc);
+ buffer_free(&wioc->encinput);
+ buffer_free(&wioc->encoutput);
+ buffer_free(&wioc->rawinput);
+ if (wioc->io_tag) {
+ g_clear_handle_id(&wioc->io_tag, g_source_remove);
+ }
+ if (wioc->io_err) {
+ g_clear_pointer(&wioc->io_err, error_free);
+ }
return qio_channel_close(wioc->master, errp);
}
--
2.50.1
next prev parent reply other threads:[~2025-09-30 11:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-30 11:08 [PATCH 0/2] io: fix crash in VNC websock server when client quits early Daniel P. Berrangé
2025-09-30 11:08 ` Daniel P. Berrangé [this message]
2025-09-30 11:21 ` [PATCH 1/2] io: move websock resource release to close method Marc-André Lureau
2025-09-30 11:28 ` Daniel P. Berrangé
2025-09-30 11:08 ` [PATCH 2/2] io: fix use after free in websocket handshake code Daniel P. Berrangé
2025-09-30 11:26 ` Marc-André Lureau
2025-09-30 11:30 ` Daniel P. Berrangé
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=20250930110834.2551757-2-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=marcandre.lureau@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=rid@cylo.io \
/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.