]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Allow to create radix tree from the pool
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 23 Apr 2018 11:41:17 +0000 (12:41 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 23 Apr 2018 11:41:17 +0000 (12:41 +0100)
src/libutil/radix.c
src/libutil/radix.h

index 8c22584595d054b28dc79c1ce2e41c9b39424239..3ef47117466eb3cd63aa3b5a725365ebe9ee9120 100644 (file)
@@ -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);
+               }
        }
 }
 
index c04528000deee24b4b9e39f93d1e10f02056080c..be75b1b7f529ea7c84a558ef293919f77d352fa5 100644 (file)
@@ -71,6 +71,8 @@ void radix_destroy_compressed (radix_compressed_t *tree);
  */
 radix_compressed_t *radix_create_compressed (void);
 
+radix_compressed_t *radix_create_compressed_with_pool (rspamd_mempool_t *pool);
+
 /**
  * Insert list of ip addresses and masks to the radix tree
  * @param list string line of addresses