aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/trie.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2015-04-19 02:45:29 -0300
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2015-04-19 02:45:29 -0300
commit8f4cba86a56cd69d95b07dda7e002f33cbe6ba62 (patch)
tree9e25ebf9043a0dc70dd721f3b20704fa572b9674 /src/utils/trie.c
parent1826b5ad70ebd5db751ed0d4eee6f857a7001100 (diff)
downloadblogc-8f4cba86a56cd69d95b07dda7e002f33cbe6ba62.tar.gz
blogc-8f4cba86a56cd69d95b07dda7e002f33cbe6ba62.tar.bz2
blogc-8f4cba86a56cd69d95b07dda7e002f33cbe6ba62.zip
trie: fixed memory leak when replacing existing key
Diffstat (limited to 'src/utils/trie.c')
-rw-r--r--src/utils/trie.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/utils/trie.c b/src/utils/trie.c
index f1b77eb..e0ac1af 100644
--- a/src/utils/trie.c
+++ b/src/utils/trie.c
@@ -82,8 +82,9 @@ b_trie_insert(b_trie_t *trie, const char *key, void *data)
parent = tmp;
- if (previous == NULL || parent != NULL)
+ if (previous == NULL || parent != NULL) {
goto clean;
+ }
current = b_malloc(sizeof(b_trie_node_t));
current->key = *key;
@@ -95,6 +96,8 @@ b_trie_insert(b_trie_t *trie, const char *key, void *data)
clean:
if (*key == '\0') {
+ if (parent->data != NULL && trie->free_func != NULL)
+ trie->free_func(parent->data);
parent->data = data;
break;
}