diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-04-23 12:41:17 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-04-23 12:41:17 +0100 |
commit | fc23f700aa82df48915a117d3c6d823f5ad82332 (patch) | |
tree | f1fd48a6bfd81f079a3320b82165551049d31a0f /src/libutil/radix.c | |
parent | 0bdb02adef792705f01eb2e9f1a153ceec26f4a7 (diff) | |
download | rspamd-fc23f700aa82df48915a117d3c6d823f5ad82332.tar.gz rspamd-fc23f700aa82df48915a117d3c6d823f5ad82332.zip |
[Minor] Allow to create radix tree from the pool
Diffstat (limited to 'src/libutil/radix.c')
-rw-r--r-- | src/libutil/radix.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/libutil/radix.c b/src/libutil/radix.c index 8c2258459..3ef471174 100644 --- a/src/libutil/radix.c +++ b/src/libutil/radix.c @@ -40,8 +40,9 @@ INIT_LOG_MODULE(radix) struct radix_tree_compressed { rspamd_mempool_t *pool; - size_t size; struct btrie *tree; + size_t size; + gboolean own_pool; }; uintptr_t @@ -116,7 +117,7 @@ radix_create_compressed (void) { radix_compressed_t *tree; - tree = g_malloc0 (sizeof (*tree)); + tree = g_malloc (sizeof (*tree)); if (tree == NULL) { return NULL; } @@ -124,6 +125,21 @@ radix_create_compressed (void) tree->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL); tree->size = 0; tree->tree = btrie_init (tree->pool); + tree->own_pool = TRUE; + + return tree; +} + +radix_compressed_t * +radix_create_compressed_with_pool (rspamd_mempool_t *pool) +{ + radix_compressed_t *tree; + + tree = rspamd_mempool_alloc (pool, sizeof (*tree)); + tree->pool = pool; + tree->size = 0; + tree->tree = btrie_init (tree->pool); + tree->own_pool = FALSE; return tree; } @@ -132,8 +148,10 @@ void radix_destroy_compressed (radix_compressed_t *tree) { if (tree) { - rspamd_mempool_delete (tree->pool); - g_free (tree); + if (tree->own_pool) { + rspamd_mempool_delete (tree->pool); + g_free (tree); + } } } |