summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--Src/Zle/zle_keymap.c22
-rw-r--r--Test/X03zlebindkey.ztst15
3 files changed, 40 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index b7721e856..7136b210a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2022-01-27 dana <dana@dana.is>
+ * Jun-ichi Takimoto: 49377: Src/Zle/zle_keymap.c,
+ Test/X03zlebindkey.ztst: fix segfault by 'bindkey -d' with
+ reordered keymapnamtab
+
* Jun-ichi Takimoto: 47560: configure.ac, aczsh.m4: add necessary
includes or prototypes for the tests in configure (fix errors in
macOS 11)
diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c
index d13aed594..49b2a26ad 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.
diff --git a/Test/X03zlebindkey.ztst b/Test/X03zlebindkey.ztst
index 298d7df5d..e5aac7379 100644
--- a/Test/X03zlebindkey.ztst
+++ b/Test/X03zlebindkey.ztst
@@ -143,3 +143,18 @@
>CURSOR: 18
>BUFFER: echo $(( ##x ) ##x ) y
>CURSOR: 22
+
+ bindkey -d
+ for name in a b c d e; bindkey -N $name
+ bindkey -d
+ bindkey -l
+0:delete all keymaps after expanding keymapnamtab
+>.safe
+>command
+>emacs
+>isearch
+>main
+>vicmd
+>viins
+>viopp
+>visual