From d362ed1eb9a6f3f91aff43df5b3a32c948c6a827 Mon Sep 17 00:00:00 2001 From: YaoBing Xiao Date: Wed, 4 Feb 2026 21:11:29 +0800 Subject: [PATCH] xwayland: fix wl_array rollback when adding selection targets Ensure mime_types and mime_types_atoms remain in sync when wl_array_add() fails. Roll back the partially added entry and free the allocated mime type to avoid leaks and inconsistent state. --- xwayland/selection/incoming.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xwayland/selection/incoming.c b/xwayland/selection/incoming.c index 72f82c279..85d7775cd 100644 --- a/xwayland/selection/incoming.c +++ b/xwayland/selection/incoming.c @@ -381,13 +381,15 @@ static bool source_get_targets(struct wlr_xwm_selection *selection, free(mime_type); break; } - *mime_type_ptr = mime_type; xcb_atom_t *atom_ptr = wl_array_add(mime_types_atoms, sizeof(*atom_ptr)); if (atom_ptr == NULL) { + mime_types->size -= sizeof(*mime_type_ptr); + free(mime_type); break; } + *mime_type_ptr = mime_type; *atom_ptr = value[i]; } }