From 077170cfb61c9a1e58ff0ecedc858a307b2d3fd9 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 10 Jun 2026 14:06:45 +0000 Subject: [PATCH] While grouped sessions are being killed, it can leave session which are not really useful as targets (no active pane or current window) in the tree. Make cmd_find_best_session skip these. GitHub issue 5167. --- usr.bin/tmux/cmd-find.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/usr.bin/tmux/cmd-find.c b/usr.bin/tmux/cmd-find.c index c420a4c2884..004ecbbd4df 100644 --- a/usr.bin/tmux/cmd-find.c +++ b/usr.bin/tmux/cmd-find.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-find.c,v 1.84 2025/12/22 08:35:04 nicm Exp $ */ +/* $OpenBSD: cmd-find.c,v 1.85 2026/06/10 14:06:45 nicm Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott @@ -148,6 +148,18 @@ cmd_find_session_better(struct session *s, struct session *than, int flags) return (timercmp(&s->activity_time, &than->activity_time, >)); } +/* Can this session be usefully targeted? */ +static int +cmd_find_session_valid(struct session *s) +{ + if (!session_alive(s) || + s->curw == NULL || + s->curw->window == NULL || + s->curw->window->active == NULL) + return (0); + return (1); +} + /* Find best session from a list, or all if list is NULL. */ static struct session * cmd_find_best_session(struct session **slist, u_int ssize, int flags) @@ -160,11 +172,15 @@ cmd_find_best_session(struct session **slist, u_int ssize, int flags) s = NULL; if (slist != NULL) { for (i = 0; i < ssize; i++) { + if (!cmd_find_session_valid(slist[i])) + continue; if (cmd_find_session_better(slist[i], s, flags)) s = slist[i]; } } else { RB_FOREACH(s_loop, sessions, &sessions) { + if (!cmd_find_session_valid(s_loop)) + continue; if (cmd_find_session_better(s_loop, s, flags)) s = s_loop; }