=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/key-bindings.c,v retrieving revision 1.105 retrieving revision 1.106 diff -c -r1.105 -r1.106 *** src/usr.bin/tmux/key-bindings.c 2019/12/19 09:22:33 1.105 --- src/usr.bin/tmux/key-bindings.c 2020/01/05 20:39:25 1.106 *************** *** 1,4 **** ! /* $OpenBSD: key-bindings.c,v 1.105 2019/12/19 09:22:33 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: key-bindings.c,v 1.106 2020/01/05 20:39:25 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 85,90 **** --- 85,98 ---- return (0); } + static void + key_bindings_free(struct key_table *table, struct key_binding *bd) + { + RB_REMOVE(key_bindings, &table->key_bindings, bd); + cmd_list_free(bd->cmdlist); + free(bd); + } + struct key_table * key_bindings_get_table(const char *name, int create) { *************** *** 126,136 **** if (--table->references != 0) return; ! RB_FOREACH_SAFE(bd, key_bindings, &table->key_bindings, bd1) { ! RB_REMOVE(key_bindings, &table->key_bindings, bd); ! cmd_list_free(bd->cmdlist); ! free(bd); ! } free((void *)table->name); free(table); --- 134,141 ---- if (--table->references != 0) return; ! RB_FOREACH_SAFE(bd, key_bindings, &table->key_bindings, bd1) ! key_bindings_free(table, bd); free((void *)table->name); free(table); *************** *** 162,178 **** struct cmd_list *cmdlist) { struct key_table *table; ! struct key_binding bd_find, *bd; table = key_bindings_get_table(name, 1); ! bd_find.key = (key & ~KEYC_XTERM); ! bd = RB_FIND(key_bindings, &table->key_bindings, &bd_find); ! if (bd != NULL) { ! RB_REMOVE(key_bindings, &table->key_bindings, bd); ! cmd_list_free(bd->cmdlist); ! free(bd); ! } bd = xcalloc(1, sizeof *bd); bd->key = key; --- 167,179 ---- struct cmd_list *cmdlist) { struct key_table *table; ! struct key_binding *bd; table = key_bindings_get_table(name, 1); ! bd = key_bindings_get(table, key & ~KEYC_XTERM); ! if (bd != NULL) ! key_bindings_free(table, bd); bd = xcalloc(1, sizeof *bd); bd->key = key; *************** *** 187,206 **** key_bindings_remove(const char *name, key_code key) { struct key_table *table; ! struct key_binding bd_find, *bd; table = key_bindings_get_table(name, 0); if (table == NULL) return; ! bd_find.key = (key & ~KEYC_XTERM); ! bd = RB_FIND(key_bindings, &table->key_bindings, &bd_find); if (bd == NULL) return; ! ! RB_REMOVE(key_bindings, &table->key_bindings, bd); ! cmd_list_free(bd->cmdlist); ! free(bd); if (RB_EMPTY(&table->key_bindings)) { RB_REMOVE(key_tables, &key_tables, table); --- 188,203 ---- key_bindings_remove(const char *name, key_code key) { struct key_table *table; ! struct key_binding *bd; table = key_bindings_get_table(name, 0); if (table == NULL) return; ! bd = key_bindings_get(table, key & ~KEYC_XTERM); if (bd == NULL) return; ! key_bindings_free(table, bd); if (RB_EMPTY(&table->key_bindings)) { RB_REMOVE(key_tables, &key_tables, table);