summary refs log tree commit diff
path: root/Src/Zle/zle_keymap.c
diff options
context:
space:
mode:
authorJun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>2021-09-08 09:51:43 +0900
committerJun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>2021-09-08 09:51:43 +0900
commit2a7945a900c8a1b1866ad31ee5e95db5b0ddb50a (patch)
tree104fbaa1271df14eb77c7f6c9c07076cbde33ed7 /Src/Zle/zle_keymap.c
parentbb61da36aaeeaa70413cdf5bc66d7a71194f93e5 (diff)
downloadzsh-2a7945a900c8a1b1866ad31ee5e95db5b0ddb50a.tar.gz
zsh-2a7945a900c8a1b1866ad31ee5e95db5b0ddb50a.tar.xz
zsh-2a7945a900c8a1b1866ad31ee5e95db5b0ddb50a.zip
49377: fix segfault by 'bindkey -d' with reordered keymapnamtab
Diffstat (limited to 'Src/Zle/zle_keymap.c')
-rw-r--r--Src/Zle/zle_keymap.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c
index 2389ab754..d90838f03 100644
--- a/Src/Zle/zle_keymap.c
+++ b/Src/Zle/zle_keymap.c
@@ -155,7 +155,7 @@ createkeymapnamtab(void)
     keymapnamtab = newhashtable(7, "keymapnamtab", NULL);
 
     keymapnamtab->hash        = hasher;
-    keymapnamtab->emptytable  = emptyhashtable;
+    keymapnamtab->emptytable  = emptykeymapnamtab;
     keymapnamtab->filltable   = NULL;
     keymapnamtab->cmpnodes    = strcmp;
     keymapnamtab->addnode     = addhashnode;
@@ -178,6 +178,26 @@ makekeymapnamnode(Keymap keymap)
     return kmn;
 }
 
+/**/
+static void
+emptykeymapnamtab(HashTable ht)
+{
+    struct hashnode *hn, *hp;
+    int i;
+
+    for (i = 0; i < ht->hsize; i++) {
+	for (hn = ht->nodes[i]; hn;) {
+	    KeymapName kmn = (KeymapName) hn;
+	    hp = hn->next;
+	    zsfree(kmn->nam);
+	    unrefkeymap(kmn->keymap);
+	    zfree(kmn, sizeof(*kmn));
+	    hn = hp;
+	}
+	ht->nodes[i] = NULL;
+    }
+    ht->ct = 0;
+}
 
 /*
  * Reference a keymap from a keymapname.