diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/renderer.c | 8 | ||||
-rw-r--r-- | src/utils.c | 10 |
2 files changed, 9 insertions, 9 deletions
diff --git a/src/renderer.c b/src/renderer.c index 351dfb1..c9cc15b 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -111,10 +111,10 @@ blogc_format_variable(const char *name, sb_trie_t *global, sb_trie_t *local, else value = blogc_get_variable(var, global, local); - free(var); - - if (value == NULL) + if (value == NULL) { + free(var); return NULL; + } char *rv = NULL; @@ -132,6 +132,8 @@ blogc_format_variable(const char *name, sb_trie_t *global, sb_trie_t *local, rv = sb_strdup(value); } + free(var); + if (len > 0) { char *tmp = sb_strndup(rv, len); free(rv); diff --git a/src/utils.c b/src/utils.c index d7362a6..9a39c61 100644 --- a/src/utils.c +++ b/src/utils.c @@ -622,22 +622,19 @@ sb_trie_foreach_node(sb_trie_node_t *node, sb_string_t *str, return; if (node->key == '\0') { - char *tmp = sb_string_free(str, false); - func(tmp, node->data, user_data); - free(tmp); + func(str->str, node->data, user_data); + return; } if (node->child != NULL) { sb_string_t *child = sb_string_dup(str); child = sb_string_append_c(child, node->key); sb_trie_foreach_node(node->child, child, func, user_data); + sb_string_free(child, true); } if (node->next != NULL) sb_trie_foreach_node(node->next, str, func, user_data); - - if (node->child != NULL && node->next == NULL) - sb_string_free(str, true); } @@ -650,4 +647,5 @@ sb_trie_foreach(sb_trie_t *trie, sb_trie_foreach_func_t func, sb_string_t *str = sb_string_new(); sb_trie_foreach_node(trie->root, str, func, user_data); + sb_string_free(str, true); } |