vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit a2e7a5af431408e9ab9fefa40d0e0151b8fc9977
parent e9ac65508dedd68d68dfef6a53ff1c2f6949a48e
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Thu, 23 Feb 2017 17:05:37 +0100

vis: unify error path of command registration functions

Diffstat:
Mvis-cmds.c | 16++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/vis-cmds.c b/vis-cmds.c @@ -10,6 +10,14 @@ typedef struct { void *data; } CmdUser; +static void cmdfree(CmdUser *cmd) { + if (!cmd) + return; + free((char*)cmd->def.name); + free((char*)cmd->def.help); + free(cmd); +} + bool vis_cmd_register(Vis *vis, const char *name, const char *help, void *data, CmdFunc *func) { if (!name) return false; @@ -34,9 +42,7 @@ bool vis_cmd_register(Vis *vis, const char *name, const char *help, void *data, } return true; err: - free((char*)cmd->def.name); - free((char*)cmd->def.help); - free(cmd); + cmdfree(cmd); return false; } @@ -50,9 +56,7 @@ bool vis_cmd_unregister(Vis *vis, const char *name) { return false; if (!map_delete(vis->usercmds, name)) return false; - free((char*)cmd->def.name); - free((char*)cmd->def.help); - free(cmd); + cmdfree(cmd); return true; }