summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2017-03-21 19:48:08 -0700
committerMichael Pavone <pavone@retrodev.com>2017-03-21 19:48:08 -0700
commit4adb4b1013e6fbd057fe6158a911e7b860a78075 (patch)
tree3d91eb7e0b16dd57d7bddcfc7a0d83103593110e
parentf8d991fc1b1ab7ae0c3d8a0307b8b2419d152278 (diff)
Don't leak a ternary tree when building the menu's initial path
-rw-r--r--menu.c2
-rw-r--r--tern.c13
-rw-r--r--tern.h1
3 files changed, 16 insertions, 0 deletions
diff --git a/menu.c b/menu.c
index 277697e..cd5cf0c 100644
--- a/menu.c
+++ b/menu.c
@@ -177,6 +177,8 @@ void * menu_write_w(uint32_t address, void * context, uint16_t value)
tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir());
vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir());
menu->curpath = replace_vars(menu->curpath, vars, 1);
+ tern_free(vars);
+
}
if (menu->state) {
uint32_t dst = menu->latch << 16 | value;
diff --git a/tern.c b/tern.c
index 7f772b7..2036b64 100644
--- a/tern.c
+++ b/tern.c
@@ -224,3 +224,16 @@ tern_node * tern_get_node(tern_val value)
{
return value.intval & 1 ? (tern_node *)(value.intval & ~1) : NULL;
}
+
+void tern_free(tern_node *head)
+{
+ if (head->left) {
+ tern_free(head->left);
+ }
+ if (head->right) {
+ tern_free(head->right);
+ }
+ if (head->el) {
+ tern_free(head->straight.next);
+ }
+}
diff --git a/tern.h b/tern.h
index 6bc2ae9..e3a2db6 100644
--- a/tern.h
+++ b/tern.h
@@ -42,5 +42,6 @@ uint32_t tern_count(tern_node *head);
void tern_foreach(tern_node *head, iter_fun fun, void *data);
char * tern_int_key(uint32_t key, char * buf);
tern_node * tern_get_node(tern_val value);
+void tern_free(tern_node *head);
#endif //TERN_H_