From c6ae53936380970d43490a262e4af2fc1b12878d Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 2 Mar 2021 11:00:38 +0000 Subject: [PATCH] Do not use NULL active window; also do not leak window name. GitHub issue 2590 from Chester Liu. --- usr.bin/tmux/names.c | 4 +++- usr.bin/tmux/spawn.c | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/usr.bin/tmux/names.c b/usr.bin/tmux/names.c index db826680878..01462c4778c 100644 --- a/usr.bin/tmux/names.c +++ b/usr.bin/tmux/names.c @@ -1,4 +1,4 @@ -/* $OpenBSD: names.c,v 1.43 2020/10/05 11:04:40 nicm Exp $ */ +/* $OpenBSD: names.c,v 1.44 2021/03/02 11:00:38 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -109,6 +109,8 @@ default_window_name(struct window *w) { char *cmd, *s; + if (w->active == NULL) + return (xstrdup("")); cmd = cmd_stringify_argv(w->active->argc, w->active->argv); if (cmd != NULL && *cmd != '\0') s = parse_window_name(cmd); diff --git a/usr.bin/tmux/spawn.c b/usr.bin/tmux/spawn.c index 5a03c5fa80c..d44420fa6e8 100644 --- a/usr.bin/tmux/spawn.c +++ b/usr.bin/tmux/spawn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: spawn.c,v 1.26 2021/03/02 10:56:45 nicm Exp $ */ +/* $OpenBSD: spawn.c,v 1.27 2021/03/02 11:00:38 nicm Exp $ */ /* * Copyright (c) 2019 Nicholas Marriott @@ -184,7 +184,7 @@ spawn_window(struct spawn_context *sc, char **cause) NULL); options_set_number(w->options, "automatic-rename", 0); } else - w->name = xstrdup(default_window_name(w)); + w->name = default_window_name(w); } /* Switch to the new window if required. */ -- 2.20.1