From 0ad0daf479ce2b7e9979aff0d50e70a92a639a30 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 21 Mar 2024 11:30:42 +0000 Subject: [PATCH] Do not notify window-layout-changed if the window is about to be destroyed (since it may have been freed by the time the notify happens), from Romain Francoise in GitHub issue 3860. --- usr.bin/tmux/cmd-display-panes.c | 4 ++-- usr.bin/tmux/cmd-resize-pane.c | 4 ++-- usr.bin/tmux/popup.c | 4 ++-- usr.bin/tmux/resize.c | 4 ++-- usr.bin/tmux/server-fn.c | 4 ++-- usr.bin/tmux/tmux.h | 4 ++-- usr.bin/tmux/window.c | 12 +++++++----- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/usr.bin/tmux/cmd-display-panes.c b/usr.bin/tmux/cmd-display-panes.c index 2546ff729fc..7d4dc4d838b 100644 --- a/usr.bin/tmux/cmd-display-panes.c +++ b/usr.bin/tmux/cmd-display-panes.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-display-panes.c,v 1.45 2022/06/30 09:55:53 nicm Exp $ */ +/* $OpenBSD: cmd-display-panes.c,v 1.46 2024/03/21 11:30:42 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -246,7 +246,7 @@ cmd_display_panes_key(struct client *c, void *data, struct key_event *event) wp = window_pane_at_index(w, index); if (wp == NULL) return (1); - window_unzoom(w); + window_unzoom(w, 1); xasprintf(&expanded, "%%%u", wp->id); diff --git a/usr.bin/tmux/cmd-resize-pane.c b/usr.bin/tmux/cmd-resize-pane.c index 2366e922a8b..8b5a5e82108 100644 --- a/usr.bin/tmux/cmd-resize-pane.c +++ b/usr.bin/tmux/cmd-resize-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-resize-pane.c,v 1.52 2022/02/03 11:06:11 nicm Exp $ */ +/* $OpenBSD: cmd-resize-pane.c,v 1.53 2024/03/21 11:30:42 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -87,7 +87,7 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item) if (args_has(args, 'Z')) { if (w->flags & WINDOW_ZOOMED) - window_unzoom(w); + window_unzoom(w, 1); else window_zoom(wp); server_redraw_window(w); diff --git a/usr.bin/tmux/popup.c b/usr.bin/tmux/popup.c index e625506da14..8f543f83f20 100644 --- a/usr.bin/tmux/popup.c +++ b/usr.bin/tmux/popup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: popup.c,v 1.52 2023/08/15 07:01:47 nicm Exp $ */ +/* $OpenBSD: popup.c,v 1.53 2024/03/21 11:30:42 nicm Exp $ */ /* * Copyright (c) 2020 Nicholas Marriott @@ -346,7 +346,7 @@ popup_make_pane(struct popup_data *pd, enum layout_type type) u_int hlimit; const char *shell; - window_unzoom(w); + window_unzoom(w, 1); lc = layout_split_pane(wp, type, -1, 0); hlimit = options_get_number(s->options, "history-limit"); diff --git a/usr.bin/tmux/resize.c b/usr.bin/tmux/resize.c index fd965b9a24d..ee193458eaf 100644 --- a/usr.bin/tmux/resize.c +++ b/usr.bin/tmux/resize.c @@ -1,4 +1,4 @@ -/* $OpenBSD: resize.c,v 1.50 2022/02/17 09:58:47 nicm Exp $ */ +/* $OpenBSD: resize.c,v 1.51 2024/03/21 11:30:42 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -40,7 +40,7 @@ resize_window(struct window *w, u_int sx, u_int sy, int xpixel, int ypixel) /* If the window is zoomed, unzoom. */ zoomed = w->flags & WINDOW_ZOOMED; if (zoomed) - window_unzoom(w); + window_unzoom(w, 1); /* Resize the layout first. */ layout_resize(w, sx, sy); diff --git a/usr.bin/tmux/server-fn.c b/usr.bin/tmux/server-fn.c index 7ddb7e7d26c..ad01c8ae7fc 100644 --- a/usr.bin/tmux/server-fn.c +++ b/usr.bin/tmux/server-fn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-fn.c,v 1.135 2024/02/13 08:10:23 nicm Exp $ */ +/* $OpenBSD: server-fn.c,v 1.136 2024/03/21 11:30:42 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -487,6 +487,6 @@ server_check_unattached(void) void server_unzoom_window(struct window *w) { - if (window_unzoom(w) == 0) + if (window_unzoom(w, 1) == 0) server_redraw_window(w); } diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 105d18693fa..3eea22028e6 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1212 2024/02/13 08:03:50 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1213 2024/03/21 11:30:42 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -3021,7 +3021,7 @@ struct window_pane *window_add_pane(struct window *, struct window_pane *, void window_resize(struct window *, u_int, u_int, int, int); void window_pane_send_resize(struct window_pane *, u_int, u_int); int window_zoom(struct window_pane *); -int window_unzoom(struct window *); +int window_unzoom(struct window *, int); int window_push_zoom(struct window *, int, int); int window_pop_zoom(struct window *); void window_lost_pane(struct window *, struct window_pane *); diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index 7454e5e23a0..3d4361a4a12 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.288 2024/02/13 08:03:50 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.289 2024/03/21 11:30:42 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -340,7 +340,7 @@ window_destroy(struct window *w) { log_debug("window @%u destroyed (%d references)", w->id, w->references); - window_unzoom(w); + window_unzoom(w, 0); RB_REMOVE(windows, &windows, w); if (w->layout_root != NULL) @@ -666,7 +666,7 @@ window_zoom(struct window_pane *wp) } int -window_unzoom(struct window *w) +window_unzoom(struct window *w, int notify) { struct window_pane *wp; @@ -683,7 +683,9 @@ window_unzoom(struct window *w) wp->saved_layout_cell = NULL; } layout_fix_panes(w, NULL); - notify_window("window-layout-changed", w); + + if (notify) + notify_window("window-layout-changed", w); return (0); } @@ -697,7 +699,7 @@ window_push_zoom(struct window *w, int always, int flag) w->flags |= WINDOW_WASZOOMED; else w->flags &= ~WINDOW_WASZOOMED; - return (window_unzoom(w) == 0); + return (window_unzoom(w, 1) == 0); } int -- 2.20.1