summaryrefslogtreecommitdiffstats
path: root/key-bindings.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2010-06-26 18:20:53 +0000
committerNicholas Marriott <nicm@openbsd.org>2010-06-26 18:20:53 +0000
commit42e24139788d76f00896005df0f745d9e022709a (patch)
treeccc08279c4c2f4162b42b07112ae3fe340c81358 /key-bindings.c
parentef7293379f00b85cb96dd0dff128bb503e87612b (diff)
Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the same command is going to be executed again (for example if you "bind-key a bind-key b ..."). Making a copy is hard, so instead add a reference count to the cmd_list. While here, also print bind-key -n and the rest of the flags properly. Fixes problem reported by mcbride@.
Diffstat (limited to 'key-bindings.c')
-rw-r--r--key-bindings.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/key-bindings.c b/key-bindings.c
index ac4039f9..2a039af0 100644
--- a/key-bindings.c
+++ b/key-bindings.c
@@ -178,14 +178,15 @@ key_bindings_init(void)
for (i = 0; i < nitems(table); i++) {
cmdlist = xmalloc(sizeof *cmdlist);
- TAILQ_INIT(cmdlist);
+ TAILQ_INIT(&cmdlist->list);
+ cmdlist->references = 1;
cmd = xmalloc(sizeof *cmd);
cmd->entry = table[i].entry;
cmd->data = NULL;
if (cmd->entry->init != NULL)
cmd->entry->init(cmd, table[i].key);
- TAILQ_INSERT_HEAD(cmdlist, cmd, qentry);
+ TAILQ_INSERT_HEAD(&cmdlist->list, cmd, qentry);
key_bindings_add(
table[i].key | KEYC_PREFIX, table[i].can_repeat, cmdlist);
@@ -259,7 +260,7 @@ key_bindings_dispatch(struct key_binding *bd, struct client *c)
ctx.cmdclient = NULL;
readonly = 1;
- TAILQ_FOREACH(cmd, bd->cmdlist, qentry) {
+ TAILQ_FOREACH(cmd, &bd->cmdlist->list, qentry) {
if (!(cmd->entry->flags & CMD_READONLY))
readonly = 0;
}