diff options
author | Thomas Adam <thomas@xteddy.org> | 2021-08-20 22:01:46 +0100 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2021-08-20 22:01:46 +0100 |
commit | b0da0cee4d54aa64db0f49eee509a76fd89d6f68 (patch) | |
tree | 1e54ddb0b113708c46e80d342d10be74cdf7b176 /cmd-new-window.c | |
parent | 944fde7c57c4f3caebb04cfc3943a81ee9729de8 (diff) | |
parent | d589be6c65c7295880bb84cd875baab2f77d5067 (diff) | |
download | rtmux-b0da0cee4d54aa64db0f49eee509a76fd89d6f68.tar.gz rtmux-b0da0cee4d54aa64db0f49eee509a76fd89d6f68.tar.bz2 rtmux-b0da0cee4d54aa64db0f49eee509a76fd89d6f68.zip |
Merge branch 'obsd-master' into master
Diffstat (limited to 'cmd-new-window.c')
-rw-r--r-- | cmd-new-window.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/cmd-new-window.c b/cmd-new-window.c index 712e2a79..f24de8e9 100644 --- a/cmd-new-window.c +++ b/cmd-new-window.c @@ -55,16 +55,15 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) struct client *c = cmdq_get_client(item); struct cmd_find_state *current = cmdq_get_current(item); struct cmd_find_state *target = cmdq_get_target(item); - struct spawn_context sc; + struct spawn_context sc = { 0 }; struct client *tc = cmdq_get_target_client(item); struct session *s = target->s; - struct winlink *wl = target->wl; + struct winlink *wl = target->wl, *new_wl = NULL; int idx = target->idx, before; - struct winlink *new_wl = NULL; char *cause = NULL, *cp; - const char *template, *add, *name; + const char *template, *name; struct cmd_find_state fs; - struct args_value *value; + struct args_value *av; /* * If -S and -n are given and -t is not and a single window with this @@ -94,7 +93,6 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) } } - before = args_has(args, 'b'); if (args_has(args, 'a') || before) { idx = winlink_shuffle_up(s, wl, before); @@ -102,20 +100,18 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) idx = target->idx; } - memset(&sc, 0, sizeof sc); sc.item = item; sc.s = s; sc.tc = tc; sc.name = args_get(args, 'n'); - sc.argc = args->argc; - sc.argv = args->argv; + args_vector(args, &sc.argc, &sc.argv); sc.environ = environ_create(); - add = args_first_value(args, 'e', &value); - while (add != NULL) { - environ_put(sc.environ, add, 0); - add = args_next_value(&value); + av = args_first_value(args, 'e'); + while (av != NULL) { + environ_put(sc.environ, av->value, 0); + av = args_next_value(av); } sc.idx = idx; @@ -130,6 +126,9 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) if ((new_wl = spawn_window(&sc, &cause)) == NULL) { cmdq_error(item, "create window failed: %s", cause); free(cause); + if (sc.argv != NULL) + cmd_free_argv(sc.argc, sc.argv); + environ_free(sc.environ); return (CMD_RETURN_ERROR); } if (!args_has(args, 'd') || new_wl == s->curw) { @@ -150,6 +149,8 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) cmd_find_from_winlink(&fs, new_wl, 0); cmdq_insert_hook(s, item, &fs, "after-new-window"); + if (sc.argv != NULL) + cmd_free_argv(sc.argc, sc.argv); environ_free(sc.environ); return (CMD_RETURN_NORMAL); } |