From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH 45/60] ui/vnc: fix vnc_display_init() leak on failure
Date: Tue, 24 Mar 2026 14:47:20 +0000 [thread overview]
Message-ID: <acKj-I6rEVPPXXry@redhat.com> (raw)
In-Reply-To: <20260317-qemu-vnc-v1-45-48eb1dcf7b76@redhat.com>
On Tue, Mar 17, 2026 at 12:50:59PM +0400, Marc-André Lureau wrote:
> Do not add the display state to the vnc list, if the initialization
> failed. Add vnc_display_free(), to free the display state and associated
> data in such case. The function is meant to be public and reused in the
> following changes.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> ui/keymaps.h | 1 +
> ui/keymaps.c | 13 ++++++++++---
> ui/vnc.c | 30 ++++++++++++++++++++++++++----
> 3 files changed, 37 insertions(+), 7 deletions(-)
>
> diff --git a/ui/keymaps.h b/ui/keymaps.h
> index 3d52c0882a1..e8917e56404 100644
> --- a/ui/keymaps.h
> +++ b/ui/keymaps.h
> @@ -54,6 +54,7 @@ typedef struct kbd_layout_t kbd_layout_t;
>
> kbd_layout_t *init_keyboard_layout(const name2keysym_t *table,
> const char *language, Error **errp);
> +void kbd_layout_free(kbd_layout_t *k);
> int keysym2scancode(kbd_layout_t *k, int keysym,
> QKbdState *kbd, bool down);
> int keycode_is_keypad(kbd_layout_t *k, int keycode);
> diff --git a/ui/keymaps.c b/ui/keymaps.c
> index 2359dbfe7e6..d1b3f43dc8a 100644
> --- a/ui/keymaps.c
> +++ b/ui/keymaps.c
> @@ -178,6 +178,14 @@ out:
> return ret;
> }
>
> +void kbd_layout_free(kbd_layout_t *k)
> +{
> + if (!k) {
> + return;
> + }
> + g_hash_table_unref(k->hash);
> + g_free(k);
> +}
>
> kbd_layout_t *init_keyboard_layout(const name2keysym_t *table,
> const char *language, Error **errp)
> @@ -185,10 +193,9 @@ kbd_layout_t *init_keyboard_layout(const name2keysym_t *table,
> kbd_layout_t *k;
>
> k = g_new0(kbd_layout_t, 1);
> - k->hash = g_hash_table_new(NULL, NULL);
> + k->hash = g_hash_table_new_full(NULL, NULL, NULL, g_free);
> if (parse_keyboard_layout(k, table, language, errp) < 0) {
> - g_hash_table_unref(k->hash);
> - g_free(k);
> + kbd_layout_free(k);
> return NULL;
> }
> return k;
This is fixing a memory leak in init_keyboard_layout that's separate
from the VNC leak, so these ui/keymaps.c should be their own commit.
> diff --git a/ui/vnc.c b/ui/vnc.c
> index 763b13acbde..115ff8a988e 100644
> --- a/ui/vnc.c
> +++ b/ui/vnc.c
> @@ -3421,6 +3421,8 @@ static void vmstate_change_handler(void *opaque, bool running, RunState state)
> update_displaychangelistener(&vd->dcl, VNC_REFRESH_INTERVAL_BASE);
> }
>
> +static void vnc_display_free(VncDisplay *vd);
> +
> void vnc_display_init(const char *id, Error **errp)
> {
> VncDisplay *vd;
> @@ -3430,8 +3432,9 @@ void vnc_display_init(const char *id, Error **errp)
> }
> vd = g_malloc0(sizeof(*vd));
>
> + qemu_mutex_init(&vd->mutex);
> vd->id = g_strdup(id);
> - QTAILQ_INSERT_TAIL(&vnc_displays, vd, next);
> + vd->dcl.ops = &dcl_ops;
>
> QTAILQ_INIT(&vd->clients);
> vd->expires = TIME_MAX;
> @@ -3445,22 +3448,22 @@ void vnc_display_init(const char *id, Error **errp)
> }
>
> if (!vd->kbd_layout) {
> + vnc_display_free(vd);
> return;
> }
>
> vd->share_policy = VNC_SHARE_POLICY_ALLOW_EXCLUSIVE;
> vd->connections_limit = 32;
>
> - qemu_mutex_init(&vd->mutex);
> vnc_start_worker_thread();
>
> - vd->dcl.ops = &dcl_ops;
> register_displaychangelistener(&vd->dcl);
> vd->kbd = qkbd_state_init(vd->dcl.con);
> vd->vmstate_handler_entry = qemu_add_vm_change_state_handler(
> &vmstate_change_handler, vd);
> -}
>
> + QTAILQ_INSERT_TAIL(&vnc_displays, vd, next);
> +}
>
> static void vnc_display_close(VncDisplay *vd)
> {
> @@ -3504,6 +3507,25 @@ static void vnc_display_close(VncDisplay *vd)
> #endif
> }
>
> +static void vnc_display_free(VncDisplay *vd)
> +{
> + if (!vd) {
> + return;
> + }
> + vnc_display_close(vd);
> + unregister_displaychangelistener(&vd->dcl);
> + qkbd_state_free(vd->kbd);
> + qemu_del_vm_change_state_handler(vd->vmstate_handler_entry);
> + kbd_layout_free(vd->kbd_layout);
> + qemu_mutex_destroy(&vd->mutex);
> + if (QTAILQ_IN_USE(vd, next)) {
> + QTAILQ_REMOVE(&vnc_displays, vd, next);
> + }
> + g_free(vd->id);
> + g_free(vd);
> +}
If we're introducing this we need to answer the earlier questions
in this series about killing off the VNC worker thread, as IMHO,
we should not leave the thread running if we're claiming to be
able to free VncDisplay state.
> +
> +
> int vnc_display_password(const char *id, const char *password, Error **errp)
> {
> VncDisplay *vd = vnc_display_find(id);
>
> --
> 2.53.0
>
>
With regards,
Daniel
--
|: https://berrange.com ~~ https://hachyderm.io/@berrange :|
|: https://libvirt.org ~~ https://entangle-photo.org :|
|: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
next prev parent reply other threads:[~2026-03-24 14:47 UTC|newest]
Thread overview: 152+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-17 8:50 [PATCH 00/60] ui: add standalone VNC server over D-Bus Marc-André Lureau
2026-03-17 8:50 ` [PATCH 01/60] ui/vnc-jobs: fix VncRectEntry leak on job cleanup Marc-André Lureau
2026-03-24 13:43 ` Daniel P. Berrangé
2026-03-31 14:28 ` Michael Tokarev
2026-03-17 8:50 ` [PATCH 02/60] ui/vnc-jobs: clear source tag Marc-André Lureau
2026-03-24 13:44 ` Daniel P. Berrangé
2026-03-17 8:50 ` [PATCH 03/60] ui/vnc-jobs: remove needless buffer_reset() before end Marc-André Lureau
2026-03-24 13:45 ` Daniel P. Berrangé
2026-03-17 8:50 ` [PATCH 04/60] ui/vnc: clarify intent using buffer_empty() function Marc-André Lureau
2026-03-24 13:45 ` Daniel P. Berrangé
2026-03-17 8:50 ` [PATCH 05/60] ui/vnc-jobs: vnc_has_job_locked() argument cannot be NULL Marc-André Lureau
2026-03-24 13:46 ` Daniel P. Berrangé
2026-03-17 8:50 ` [PATCH 06/60] ui/vnc-jobs: remove dead VncJobQueue.exit Marc-André Lureau
2026-03-24 13:49 ` Daniel P. Berrangé
2026-03-17 8:50 ` [PATCH 07/60] ui/vnc-jobs: remove vnc_queue_clear() Marc-André Lureau
2026-03-24 13:51 ` Daniel P. Berrangé
2026-03-17 8:50 ` [PATCH 08/60] ui/vnc-jobs: narrow taking the lock when pushing empty jobs Marc-André Lureau
2026-03-24 13:53 ` Daniel P. Berrangé
2026-03-24 14:04 ` Marc-André Lureau
2026-03-17 8:50 ` [PATCH 09/60] ui/vnc-jobs: drop redundant (and needless) qemu_thread_get_self() Marc-André Lureau
2026-03-24 14:00 ` Daniel P. Berrangé
2026-03-17 8:50 ` [PATCH 10/60] ui/console-vc: fix off-by-one in CSI J 2 (clear entire screen) Marc-André Lureau
2026-03-24 14:03 ` Daniel P. Berrangé
2026-03-17 8:50 ` [PATCH 11/60] ui/console-vc: add UTF-8 input decoding with CP437 rendering Marc-André Lureau
2026-03-24 14:07 ` Daniel P. Berrangé
2026-03-24 14:17 ` Marc-André Lureau
2026-03-24 15:42 ` Daniel P. Berrangé
2026-03-25 5:35 ` Markus Armbruster
2026-03-25 6:48 ` Marc-André Lureau
2026-04-02 11:44 ` Marc-André Lureau
2026-04-02 14:39 ` Markus Armbruster
2026-04-03 10:16 ` Marc-André Lureau
2026-03-17 8:50 ` [PATCH 12/60] ui/console-vc: ignore string-type escape sequences Marc-André Lureau
2026-03-17 8:50 ` [PATCH 13/60] ui/console-vc: fix comment shift-out/in comments Marc-André Lureau
2026-03-24 14:11 ` Daniel P. Berrangé
2026-03-17 8:50 ` [PATCH 14/60] ui/console: dispatch get_label() through QOM virtual method Marc-André Lureau
2026-03-24 14:14 ` Daniel P. Berrangé
2026-03-17 8:50 ` [PATCH 15/60] ui/console-vc: introduce QemuVT100 Marc-André Lureau
2026-04-01 9:08 ` Philippe Mathieu-Daudé
2026-04-01 9:24 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 16/60] ui/console-vc: set vt100 associated pixman image Marc-André Lureau
2026-04-01 9:09 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 17/60] ui/console-vc: vga_putcharxy()->vt100_putcharxy() Marc-André Lureau
2026-04-01 9:10 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 18/60] ui/console-vc: make invalidate_xy() take vt100 Marc-André Lureau
2026-04-01 9:10 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 19/60] ui/console-vc: make show_cursor() " Marc-André Lureau
2026-04-01 9:11 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 20/60] ui/console-vc: decouple VT100 display updates via function pointer Marc-André Lureau
2026-04-01 9:13 ` Philippe Mathieu-Daudé
2026-04-01 9:17 ` Philippe Mathieu-Daudé
2026-04-01 13:45 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 21/60] ui/console-vc: console_refresh() -> vt100_refresh() Marc-André Lureau
2026-04-01 9:14 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 22/60] ui/console-vc: move cursor blinking logic into VT100 layer Marc-André Lureau
2026-03-17 8:50 ` [PATCH 23/60] ui/console-vc: console_scroll() -> vt100_scroll() Marc-André Lureau
2026-04-01 9:19 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 24/60] ui/console-vc: refactor text_console_resize() into vt100_set_image() Marc-André Lureau
2026-04-01 9:20 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 25/60] ui/console-vc: move vc_put_lf() to VT100 layer as vt100_put_lf() Marc-André Lureau
2026-04-01 9:25 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 26/60] ui/console-vc: unify the write path Marc-André Lureau
2026-04-01 13:37 ` Philippe Mathieu-Daudé
2026-04-01 13:41 ` Philippe Mathieu-Daudé
2026-04-02 13:25 ` Marc-André Lureau
2026-03-17 8:50 ` [PATCH 27/60] ui/console-vc: move VT100 state machine and output FIFO into QemuVT100 Marc-André Lureau
2026-04-01 13:38 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 28/60] ui/console-vc: extract vt100_input() from vc_chr_write() Marc-André Lureau
2026-04-01 13:42 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 29/60] ui/console-vc: extract vt100_keysym() from qemu_text_console_handle_keysym() Marc-André Lureau
2026-04-01 13:43 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 30/60] ui/console-vc: extract vt100_init() and vt100_fini() Marc-André Lureau
2026-04-01 13:46 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 31/60] ui/console: remove console_ch_t typedef and console_write_ch() Marc-André Lureau
2026-04-01 13:48 ` Philippe Mathieu-Daudé
2026-04-02 13:52 ` Marc-André Lureau
2026-03-17 8:50 ` [PATCH 32/60] ui: avoid duplicating vgafont16 in each translation unit Marc-André Lureau
2026-03-24 14:22 ` Daniel P. Berrangé
2026-04-01 9:27 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 33/60] ui/vgafont: add SPDX license header Marc-André Lureau
2026-03-24 14:24 ` Daniel P. Berrangé
2026-03-17 8:50 ` [PATCH 34/60] ui: move FONT_WIDTH/HEIGHT to vgafont.h Marc-André Lureau
2026-03-24 14:25 ` Daniel P. Berrangé
2026-04-01 9:28 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 35/60] ui/console-vc: move VT100 emulation into separate unit Marc-André Lureau
2026-04-01 9:28 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 36/60] util: move datadir.c from system/ Marc-André Lureau
2026-03-24 14:27 ` Daniel P. Berrangé
2026-04-01 9:30 ` Philippe Mathieu-Daudé
2026-04-02 14:05 ` Marc-André Lureau
2026-03-17 8:50 ` [PATCH 37/60] ui: move DisplaySurface functions to display-surface.c Marc-André Lureau
2026-04-01 9:31 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 38/60] ui: make qemu_default_pixelformat() static inline Marc-André Lureau
2026-03-24 14:28 ` Daniel P. Berrangé
2026-03-17 8:50 ` [PATCH 39/60] ui: make unregister_displaychangelistener() skip unregistered Marc-André Lureau
2026-03-24 14:28 ` Daniel P. Berrangé
2026-03-17 8:50 ` [PATCH 40/60] ui: minor code simplification Marc-André Lureau
2026-03-24 14:30 ` Daniel P. Berrangé
2026-04-01 9:33 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 41/60] system: make qemu_del_vm_change_state_handler accept NULL Marc-André Lureau
2026-03-24 14:31 ` Daniel P. Berrangé
2026-03-17 8:50 ` [PATCH 42/60] ui/vnc: assert preconditions instead of silently returning Marc-André Lureau
2026-03-24 14:31 ` Daniel P. Berrangé
2026-04-01 9:33 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 43/60] ui/vnc: simplify vnc_init_func error handling Marc-André Lureau
2026-03-24 14:38 ` Daniel P. Berrangé
2026-04-04 14:00 ` Marc-André Lureau
2026-04-01 13:49 ` Philippe Mathieu-Daudé
2026-03-17 8:50 ` [PATCH 44/60] ui/vnc: VncDisplay.id is not const Marc-André Lureau
2026-03-24 14:39 ` Daniel P. Berrangé
2026-03-17 8:50 ` [PATCH 45/60] ui/vnc: fix vnc_display_init() leak on failure Marc-André Lureau
2026-03-24 14:47 ` Daniel P. Berrangé [this message]
2026-04-04 14:19 ` Marc-André Lureau
2026-04-07 8:55 ` Daniel P. Berrangé
2026-04-07 12:10 ` Marc-André Lureau
2026-03-17 8:51 ` [PATCH 46/60] ui/vnc: merge vnc_display_init() and vnc_display_open() Marc-André Lureau
2026-03-24 14:51 ` Daniel P. Berrangé
2026-03-17 8:51 ` [PATCH 47/60] ui/vnc: report an error for duplicate display id Marc-André Lureau
2026-03-24 14:52 ` Daniel P. Berrangé
2026-03-17 8:51 ` [PATCH 48/60] ui/vnc: defer listener registration until the console is known Marc-André Lureau
2026-03-24 14:53 ` Daniel P. Berrangé
2026-03-17 8:51 ` [PATCH 49/60] ui/vnc: explicitly link with png Marc-André Lureau
2026-03-24 14:56 ` Daniel P. Berrangé
2026-04-01 9:35 ` Philippe Mathieu-Daudé
2026-03-17 8:51 ` [PATCH 50/60] ui/vnc: add vnc-system unit, to allow different implementations Marc-André Lureau
2026-03-17 8:51 ` [PATCH 51/60] ui/console: remove qemu_console_is_visible() Marc-André Lureau
2026-03-24 14:57 ` Daniel P. Berrangé
2026-03-17 8:51 ` [PATCH 52/60] ui/console: simplify registering display/console change listener Marc-André Lureau
2026-04-01 9:38 ` Philippe Mathieu-Daudé
2026-03-17 8:51 ` [PATCH 53/60] ui/console: return completion status from gfx_update callback Marc-André Lureau
2026-03-17 11:43 ` BALATON Zoltan
2026-04-04 14:59 ` Marc-André Lureau
2026-03-17 8:51 ` [PATCH 54/60] ui/console: rename public API to use consistent qemu_console_ prefix Marc-André Lureau
2026-03-17 11:46 ` BALATON Zoltan
2026-04-04 15:06 ` Marc-André Lureau
2026-03-17 8:51 ` [PATCH 55/60] ui/console: move console_handle_touch_event() to input Marc-André Lureau
2026-04-01 9:39 ` Philippe Mathieu-Daudé
2026-03-17 8:51 ` [PATCH 56/60] ui: extract common sources into a static library Marc-André Lureau
2026-04-01 9:40 ` Philippe Mathieu-Daudé
2026-03-17 8:51 ` [PATCH 57/60] tests: rename the dbus-daemon helper script Marc-André Lureau
2026-03-24 15:05 ` Daniel P. Berrangé
2026-04-01 9:40 ` Philippe Mathieu-Daudé
2026-03-17 8:51 ` [PATCH 58/60] tests/qtest: fix dbus-vmstate-test compilation Marc-André Lureau
2026-03-17 12:28 ` Fabiano Rosas
2026-03-17 12:39 ` Marc-André Lureau
2026-03-17 8:51 ` [PATCH 59/60] tests/qtest: drop DBUS_VMSTATE_TEST_TMPDIR Marc-André Lureau
2026-03-17 8:51 ` [PATCH 60/60] contrib/qemu-vnc: add standalone VNC server over D-Bus Marc-André Lureau
2026-03-24 15:24 ` Daniel P. Berrangé
2026-03-24 15:44 ` Peter Maydell
2026-03-25 8:32 ` Marc-André Lureau
2026-04-01 9:43 ` Philippe Mathieu-Daudé
2026-03-24 17:36 ` [PATCH 00/60] ui: " 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=acKj-I6rEVPPXXry@redhat.com \
--to=berrange@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
/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.