diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-12-27 23:22:01 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-12-27 23:29:04 +0100 |
| commit | f52050784e7e1426eafb5e69bc2fa37219415406 (patch) | |
| tree | 52ce0d5e3137ac77969ddb256a32e26910c43c98 /vis-modes.c | |
| parent | b7c6c43b64dd88a3f3cff692bf224654aef9b1e2 (diff) | |
| download | vis-f52050784e7e1426eafb5e69bc2fa37219415406.tar.gz vis-f52050784e7e1426eafb5e69bc2fa37219415406.tar.xz | |
vis: properly free dynamic key bindings
The handling of :unmap needs to be revisited at some point.
Diffstat (limited to 'vis-modes.c')
| -rw-r--r-- | vis-modes.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/vis-modes.c b/vis-modes.c index 7008161..68771ce 100644 --- a/vis-modes.c +++ b/vis-modes.c @@ -2,6 +2,35 @@ #include "vis-core.h" #include "util.h" +KeyBinding *vis_binding_new(Vis *vis) { + KeyBinding *binding = calloc(1, sizeof *binding); + if (binding && array_add_ptr(&vis->bindings, binding)) + return binding; + free(binding); + return NULL; +} + +void vis_binding_free(Vis *vis, KeyBinding *binding) { + if (!binding) + return; + size_t len = array_length(&vis->bindings); + for (size_t i = 0; i < len; i++) { + if (binding == array_get_ptr(&vis->bindings, i)) { + if (binding->alias) + free((char*)binding->alias); + const KeyAction *action = binding->action; + if (action) { + free((char*)action->name); + free((char*)action->help); + free((KeyAction*)action); + } + free(binding); + array_remove(&vis->bindings, i); + break; + } + } +} + static Mode *mode_get(Vis *vis, enum VisMode mode) { if (mode < LENGTH(vis_modes)) return &vis_modes[mode]; |
