Do not use NULL active window; also do not leak window name. GitHub
authornicm <nicm@openbsd.org>
Tue, 2 Mar 2021 11:00:38 +0000 (11:00 +0000)
committernicm <nicm@openbsd.org>
Tue, 2 Mar 2021 11:00:38 +0000 (11:00 +0000)
issue 2590 from Chester Liu.

usr.bin/tmux/names.c
usr.bin/tmux/spawn.c

index db82668..01462c4 100644 (file)
@@ -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 <nicholas.marriott@gmail.com>
@@ -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);
index 5a03c5f..d44420f 100644 (file)
@@ -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 <nicholas.marriott@gmail.com>
@@ -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. */