]> git.neil.brown.name Git - edlib.git/commitdiff
keymap: make a local copy of any key put in a keymap.
authorNeilBrown <neil@brown.name>
Fri, 25 Dec 2015 22:34:07 +0000 (09:34 +1100)
committerNeilBrown <neil@brown.name>
Fri, 25 Dec 2015 22:34:07 +0000 (09:34 +1100)
When called from C, these are always static.  But there is no
such guarantee when called from elsewhere.

We really should refcount the 'comm' too or something like that.
For now, they are never freed.

Signed-off-by: NeilBrown <neil@brown.name>
core-keymap.c

index 30ee7abe9f4a9c95d159d169e0465d92f42fa4ab..4850b7372346c8307d9b9a3be247e7fdd849a51c 100644 (file)
@@ -159,7 +159,7 @@ void key_add(struct map *map, char *k, struct command *comm)
                (map->size - pos) * sizeof(map->keys[0]));
        memmove(map->comms+pos+ins_cnt, map->comms+pos,
                (map->size - pos) * sizeof(struct command *));
-       map->keys[pos] = k;
+       map->keys[pos] = strdup(k);
        map->comms[pos] = comm;
        if (comm2) {
                map->keys[pos+1] = k;