From 305337f6b968c36ed948b2eee6738f5ee42fc824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Wed, 28 Dec 2016 22:18:54 +0100 Subject: vis: do not free right hand side of mapping twice Fix #447 --- vis-cmds.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/vis-cmds.c b/vis-cmds.c index 969eec7..31c98f9 100644 --- a/vis-cmds.c +++ b/vis-cmds.c @@ -776,7 +776,6 @@ static bool cmd_langmap(Vis *vis, Win *win, Command *cmd, const char *argv[], Cu } static bool cmd_map(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) { - KeyBinding *binding = NULL; bool mapped = false; bool local = strstr(argv[0], "-") != NULL; enum VisMode mode = str2vismode(argv[1]); @@ -790,22 +789,18 @@ static bool cmd_map(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor } const char *lhs = argv[2]; - char *rhs = strdup(argv[3]); - if (!rhs || !(binding = vis_binding_new(vis))) + KeyBinding *binding = vis_binding_new(vis); + if (!binding || !(binding->alias = strdup(argv[3]))) goto err; - binding->alias = rhs; - if (local) mapped = vis_window_mode_map(win, mode, cmd->flags == '!', lhs, binding); else mapped = vis_mode_map(vis, mode, cmd->flags == '!', lhs, binding); err: - if (!mapped) { - free(rhs); + if (!mapped) vis_binding_free(vis, binding); - } return mapped; } -- cgit v1.2.3