Re: [dev] [tabbed] bug in cleanup function

From: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Tue, 11 Nov 2025 20:16:27 +0100

On Thu, Nov 06, 2025 at 11:49:20AM +0300, Ivan Vetrov wrote:
> Hi,
>
> In the cleanup function there is a loop
>
> for (i = 0; i < nclients; i++) {
> focus(i);
> killclient(NULL);
> XReparentWindow(dpy, clients[i]->win, root, 0, 0);
> unmanage(i);
> }
>
> which is buggy because unmanage decreases the global variable nclients by
> one and also affects the memory pointed to by clients, so it actually
> destroys only clients with even indices. I think it can be fixed by destroying
> the 0th client nclients times or by iterating in reverse order (as in the
> attached patch).
>
> Best regards,
> Ivan

> From 0752e274c09275297631b25e85322d1cfbbd236a Mon Sep 17 00:00:00 2001
> From: Ivan Vetrov <vetrov.iv5_AT_gmail.com>
> Date: Wed, 5 Nov 2025 08:28:42 +0300
> Subject: [PATCH] cleanup(): fix for loop bounds
>
> ---
> tabbed.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tabbed.c b/tabbed.c
> index aa45716..2fb5aa7 100644
> --- a/tabbed.c
> +++ b/tabbed.c
> _AT_@ -214,7 +214,7 @@ cleanup(void)
> {
> int i;
>
> - for (i = 0; i < nclients; i++) {
> + for (i = nclients - 1; i >= 0; i--) {
> focus(i);
> killclient(NULL);
> XReparentWindow(dpy, clients[i]->win, root, 0, 0);
> --
> 2.51.2
>


Hi Ivan,

Pushed, thank you!

-- 
Kind regards,
Hiltjo
Received on Tue Nov 11 2025 - 20:16:27 CET

This archive was generated by hypermail 2.3.0 : Tue Nov 11 2025 - 20:24:09 CET