From f52050784e7e1426eafb5e69bc2fa37219415406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Tue, 27 Dec 2016 23:22:01 +0100 Subject: vis: properly free dynamic key bindings The handling of :unmap needs to be revisited at some point. --- vis-lua.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'vis-lua.c') diff --git a/vis-lua.c b/vis-lua.c index e3f355b..2c41e0f 100644 --- a/vis-lua.c +++ b/vis-lua.c @@ -669,8 +669,11 @@ static int keymap(lua_State *L, Vis *vis, Win *win) { if (!key || !lua_isfunction(L, 4)) goto err; const char *help = luaL_optstring(L, 5, NULL); - if (!(binding = calloc(1, sizeof *binding)) || !(action = calloc(1, sizeof *action))) + if (!(binding = vis_binding_new(vis))) goto err; + if (!(action = calloc(1, sizeof *action))) + goto err; + binding->action = action; /* store reference to function in the registry */ lua_pushvalue(L, 4); @@ -687,8 +690,6 @@ static int keymap(lua_State *L, Vis *vis, Win *win) { }, }; - binding->action = action; - if (win) { if (!vis_window_mode_map(win, mode, true, key, binding)) goto err; @@ -700,8 +701,7 @@ static int keymap(lua_State *L, Vis *vis, Win *win) { lua_pushboolean(L, true); return 1; err: - free(binding); - free(action); + vis_binding_free(vis, binding); lua_pushboolean(L, false); return 1; } -- cgit v1.2.3