aboutsummaryrefslogtreecommitdiff
path: root/hooks.c
diff options
context:
space:
mode:
authornicm <nicm>2015-12-11 15:46:57 +0000
committernicm <nicm>2015-12-11 15:46:57 +0000
commitbd5918760ecd1f40a574ccc8a302af869f68c27f (patch)
tree61937b9355903e6810816eaf4068567df478f36e /hooks.c
parentd7e11d0af78bacc7722998509ac93be7fcffc7b4 (diff)
downloadrtmux-bd5918760ecd1f40a574ccc8a302af869f68c27f.tar.gz
rtmux-bd5918760ecd1f40a574ccc8a302af869f68c27f.tar.bz2
rtmux-bd5918760ecd1f40a574ccc8a302af869f68c27f.zip
We cannot do hooks_find and then hooks_remove because it might have come
from the parent (global) tree, instead make it remove by name like options. While here, also tidy up a few bits of options and hooks handling (use RB_FOREACH_SAFE, and a helper function for the free).
Diffstat (limited to 'hooks.c')
-rw-r--r--hooks.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/hooks.c b/hooks.c
index 95d6b9d8..6f548d23 100644
--- a/hooks.c
+++ b/hooks.c
@@ -32,7 +32,8 @@ static int hooks_cmp(struct hook *, struct hook *);
RB_PROTOTYPE(hooks_tree, hook, entry, hooks_cmp);
RB_GENERATE(hooks_tree, hook, entry, hooks_cmp);
-struct hook *hooks_find1(struct hooks *, const char *);
+static struct hook *hooks_find1(struct hooks *, const char *);
+static void hooks_free1(struct hooks *, struct hook *);
static int
hooks_cmp(struct hook *hook1, struct hook *hook2)
@@ -51,13 +52,22 @@ hooks_create(struct hooks *parent)
return (hooks);
}
+static void
+hooks_free1(struct hooks *hooks, struct hook *hook)
+{
+ RB_REMOVE(hooks_tree, &hooks->tree, hook);
+ cmd_list_free(hook->cmdlist);
+ free((char *)hook->name);
+ free(hook);
+}
+
void
hooks_free(struct hooks *hooks)
{
struct hook *hook, *hook1;
RB_FOREACH_SAFE(hook, hooks_tree, &hooks->tree, hook1)
- hooks_remove(hooks, hook);
+ hooks_free1(hooks, hook);
free(hooks);
}
@@ -79,7 +89,7 @@ hooks_add(struct hooks *hooks, const char *name, struct cmd_list *cmdlist)
struct hook *hook;
if ((hook = hooks_find1(hooks, name)) != NULL)
- hooks_remove(hooks, hook);
+ hooks_free1(hooks, hook);
hook = xcalloc(1, sizeof *hook);
hook->name = xstrdup(name);
@@ -89,15 +99,15 @@ hooks_add(struct hooks *hooks, const char *name, struct cmd_list *cmdlist)
}
void
-hooks_remove(struct hooks *hooks, struct hook *hook)
+hooks_remove(struct hooks *hooks, const char *name)
{
- RB_REMOVE(hooks_tree, &hooks->tree, hook);
- cmd_list_free(hook->cmdlist);
- free((char *) hook->name);
- free(hook);
+ struct hook *hook;
+
+ if ((hook = hooks_find1(hooks, name)) != NULL)
+ hooks_free1(hooks, hook);
}
-struct hook *
+static struct hook *
hooks_find1(struct hooks *hooks, const char *name)
{
struct hook hook;