]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Split off pool_alloconly_free_blocks_until_last()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 23 Nov 2021 13:56:10 +0000 (14:56 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 20 Dec 2021 20:51:32 +0000 (20:51 +0000)
src/lib/mempool-alloconly.c

index f037dd1235cc82bf7b89fae03f82e73f6e8f6762..e2ef5ab14001b754cee1995bf1691a54ad09791b 100644 (file)
@@ -280,6 +280,29 @@ pool_t pool_alloconly_create_clean(const char *name, size_t size)
        return pool;
 }
 
+static void
+pool_alloconly_free_blocks_until_last(struct alloconly_pool *apool)
+{
+       struct pool_block *block;
+
+       /* destroy all blocks but the oldest, which contains the
+          struct alloconly_pool allocation. */
+       while (apool->block->prev != NULL) {
+               block = apool->block;
+               apool->block = block->prev;
+
+#ifdef DEBUG
+               safe_memset(block, CLEAR_CHR, SIZEOF_POOLBLOCK + block->size);
+#else
+               if (apool->clean_frees) {
+                       safe_memset(block, CLEAR_CHR,
+                                   SIZEOF_POOLBLOCK + block->size);
+               }
+#endif
+               free(block);
+       }
+}
+
 static void pool_alloconly_destroy(struct alloconly_pool *apool)
 {
        void *block;
@@ -471,29 +494,13 @@ static void pool_alloconly_clear(pool_t pool)
 {
        struct alloconly_pool *apool =
                container_of(pool, struct alloconly_pool, pool);
-       struct pool_block *block;
        size_t base_size, avail_size;
 
 #ifdef DEBUG
        check_sentries(apool->block);
 #endif
 
-       /* destroy all blocks but the oldest, which contains the
-          struct alloconly_pool allocation. */
-       while (apool->block->prev != NULL) {
-               block = apool->block;
-               apool->block = block->prev;
-
-#ifdef DEBUG
-               safe_memset(block, CLEAR_CHR, SIZEOF_POOLBLOCK + block->size);
-#else
-               if (apool->clean_frees) {
-                       safe_memset(block, CLEAR_CHR,
-                                   SIZEOF_POOLBLOCK + block->size);
-               }
-#endif
-               free(block);
-       }
+       pool_alloconly_free_blocks_until_last(apool);
 
        /* clear the first block */
 #ifdef DEBUG