]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
liblib: Removed unused system-clean and alloconly-clean mempools.
authorTimo Sirainen <tss@iki.fi>
Fri, 3 Sep 2010 14:18:09 +0000 (15:18 +0100)
committerTimo Sirainen <tss@iki.fi>
Fri, 3 Sep 2010 14:18:09 +0000 (15:18 +0100)
They're just making the code messier and slower.

src/lib/Makefile.am
src/lib/mempool-alloconly.c
src/lib/mempool-system-clean.c [deleted file]
src/lib/mempool.h

index 61754327b72e3f07c98a1671727936ebf4c6e0a0..a0a07007181107686013b85346b3288a844a594a 100644 (file)
@@ -72,7 +72,6 @@ liblib_la_SOURCES = \
        mempool-alloconly.c \
        mempool-datastack.c \
        mempool-system.c \
-       mempool-system-clean.c \
        mempool-unsafe-datastack.c \
        mkdir-parents.c \
        mmap-anon.c \
index f725fa8697bdd4e7c718984e82ef6fc1eabe7381..e2f83a86011b03457d023ffc3b92cc4b815a72f3 100644 (file)
@@ -25,7 +25,6 @@ struct alloconly_pool {
        size_t base_size;
        bool disable_warning;
 #endif
-       bool clean_frees;
 };
 
 struct pool_block {
@@ -160,17 +159,6 @@ pool_t pool_alloconly_create(const char *name ATTR_UNUSED, size_t size)
        return &new_apool->pool;
 }
 
-pool_t pool_alloconly_create_clean(const char *name, size_t size)
-{
-       struct alloconly_pool *apool;
-       pool_t pool;
-
-       pool = pool_alloconly_create(name, size);
-       apool = (struct alloconly_pool *)pool;
-       apool->clean_frees = TRUE;
-       return pool;
-}
-
 static void pool_alloconly_destroy(struct alloconly_pool *apool)
 {
        void *block;
@@ -182,13 +170,7 @@ static void pool_alloconly_destroy(struct alloconly_pool *apool)
        block = apool->block;
 #ifdef DEBUG
        safe_memset(block, CLEAR_CHR, SIZEOF_POOLBLOCK + apool->block->size);
-#else
-       if (apool->clean_frees) {
-               safe_memset(block, CLEAR_CHR,
-                           SIZEOF_POOLBLOCK + apool->block->size);
-       }
 #endif
-
 #ifndef USE_GC
        free(block);
 #endif
@@ -380,11 +362,6 @@ static void pool_alloconly_clear(pool_t pool)
 
 #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
 #ifndef USE_GC
                free(block);
diff --git a/src/lib/mempool-system-clean.c b/src/lib/mempool-system-clean.c
deleted file mode 100644 (file)
index 8b847de..0000000
+++ /dev/null
@@ -1,175 +0,0 @@
-/* Copyright (c) 2007-2010 Dovecot authors, see the included COPYING file */
-
-/* @UNSAFE: whole file */
-
-#include "lib.h"
-#include "safe-memset.h"
-#include "mempool.h"
-
-#include <stdlib.h>
-#ifndef HAVE_MALLOC_USABLE_SIZE
-/* no extra includes needed */
-#elif defined (HAVE_MALLOC_NP_H)
-#  include <malloc_np.h> /* FreeBSD */
-#elif defined (HAVE_MALLOC_H)
-#  include <malloc.h> /* Linux */
-#endif
-
-#ifdef HAVE_GC_GC_H
-#  include <gc/gc.h>
-#elif defined (HAVE_GC_H)
-#  include <gc.h>
-#endif
-
-/* use the maximum of required memory alignment and sizeof(void *)
-   (sizeof(size_t) is assumed to be same. it always is.) */
-#if MEM_ALIGN_SIZE > SIZEOF_VOID_P
-#  define EXTRA_SIZE_SPACE MEM_ALIGN_SIZE
-#else
-#  define EXTRA_SIZE_SPACE SIZEOF_VOID_P
-#endif
-
-/* FIXME: Disabled for now, broken with Valgrind and HP-UX. */
-#undef HAVE_MALLOC_USABLE_SIZE
-
-static const char *pool_system_clean_get_name(pool_t pool);
-static void pool_system_clean_ref(pool_t pool);
-static void pool_system_clean_unref(pool_t *pool);
-static void *pool_system_clean_malloc(pool_t pool, size_t size);
-static void pool_system_clean_free(pool_t pool, void *mem);
-static void *pool_system_clean_realloc(pool_t pool, void *mem,
-                                      size_t old_size, size_t new_size);
-static void pool_system_clean_clear(pool_t pool);
-static size_t pool_system_clean_get_max_easy_alloc_size(pool_t pool);
-
-static struct pool_vfuncs static_system_clean_pool_vfuncs = {
-       pool_system_clean_get_name,
-
-       pool_system_clean_ref,
-       pool_system_clean_unref,
-
-       pool_system_clean_malloc,
-       pool_system_clean_free,
-
-       pool_system_clean_realloc,
-
-       pool_system_clean_clear,
-       pool_system_clean_get_max_easy_alloc_size
-};
-
-static struct pool static_system_clean_pool = {
-       .v = &static_system_clean_pool_vfuncs,
-
-       .alloconly_pool = FALSE,
-       .datastack_pool = FALSE
-};
-
-pool_t system_clean_pool = &static_system_clean_pool;
-
-static const char *pool_system_clean_get_name(pool_t pool ATTR_UNUSED)
-{
-       return "system clean";
-}
-
-static void pool_system_clean_ref(pool_t pool ATTR_UNUSED)
-{
-}
-
-static void pool_system_clean_unref(pool_t *pool ATTR_UNUSED)
-{
-}
-
-static size_t mem_get_size(void *mem)
-{
-#ifdef USE_GC
-       return GC_size(mem);
-#elif defined(HAVE_MALLOC_USABLE_SIZE)
-       return malloc_usable_size(mem);
-#else
-       return *((size_t *)PTR_OFFSET(mem, -EXTRA_SIZE_SPACE));
-#endif
-}
-
-static void *pool_system_clean_malloc(pool_t pool ATTR_UNUSED, size_t size)
-{
-       void *mem;
-
-       if (unlikely(size == 0 || size > SSIZE_T_MAX))
-               i_panic("Trying to allocate %"PRIuSIZE_T" bytes", size);
-
-#ifdef USE_GC
-       mem = GC_malloc(size);
-#else
-#ifndef HAVE_MALLOC_USABLE_SIZE
-       size += EXTRA_SIZE_SPACE;
-#endif
-       mem = calloc(size, 1);
-#endif
-       if (unlikely(mem == NULL)) {
-               i_fatal_status(FATAL_OUTOFMEM, "pool_system_malloc(%"PRIuSIZE_T
-                              "): Out of memory", size);
-       }
-#if !defined(USE_GC) && !defined(HAVE_MALLOC_USABLE_SIZE)
-       {
-               size_t *saved_size = mem;
-
-               *saved_size = size - EXTRA_SIZE_SPACE;
-               mem = PTR_OFFSET(mem, EXTRA_SIZE_SPACE);
-       }
-#endif
-       return mem;
-}
-
-static void pool_system_clean_free(pool_t pool ATTR_UNUSED, void *mem)
-{
-       if (mem != NULL) {
-               safe_memset(mem, 0, mem_get_size(mem));
-#ifndef USE_GC
-#ifndef HAVE_MALLOC_USABLE_SIZE
-               mem = PTR_OFFSET(mem, -EXTRA_SIZE_SPACE);
-#endif
-               free(mem);
-#endif
-       }
-}
-
-static void *pool_system_clean_realloc(pool_t pool ATTR_UNUSED, void *mem,
-                                      size_t old_size, size_t new_size)
-{
-       void *new_mem;
-       size_t old_alloc_size;
-
-       if (unlikely(new_size == 0 || new_size > SSIZE_T_MAX))
-               i_panic("Trying to allocate %"PRIuSIZE_T" bytes", new_size);
-
-       new_mem = pool_system_clean_malloc(pool, new_size);
-       if (mem != NULL) {
-#if !defined(USE_GC) && defined(HAVE_MALLOC_USABLE_SIZE)
-               i_assert(old_size == (size_t)-1 ||
-                        old_size <= malloc_usable_size(mem));
-#endif
-               old_alloc_size = mem_get_size(mem);
-               memcpy(new_mem, mem, I_MIN(old_alloc_size, new_size));
-
-               if (old_size < new_size) {
-                       /* clear new data */
-                       memset((char *)new_mem + old_size, 0,
-                              new_size - old_size);
-               }
-               pool_system_clean_free(pool, mem);
-       }
-
-        return new_mem;
-}
-
-static void ATTR_NORETURN
-pool_system_clean_clear(pool_t pool ATTR_UNUSED)
-{
-       i_panic("pool_system_clean_clear() must not be called");
-}
-
-static size_t
-pool_system_clean_get_max_easy_alloc_size(pool_t pool ATTR_UNUSED)
-{
-       return 0;
-}
index 4accac73e992a36e109002dfb32d9ed54e2c0205..fa95489319eb1855ed700387e55179dae76d9fd3 100644 (file)
@@ -49,9 +49,6 @@ struct pool {
 /* system_pool uses calloc() + realloc() + free() */
 extern pool_t system_pool;
 extern struct pool static_system_pool;
-/* Similar to pool_alloconly_create_clean(), but uses system_pool to
-   allocate the memory. */
-extern pool_t system_clean_pool;
 
 /* memory allocated from data_stack is valid only until next t_pop() call.
    No checks are performed. */
@@ -60,11 +57,6 @@ extern pool_t unsafe_data_stack_pool;
 /* Create a new alloc-only pool. Note that `size' specifies the initial
    malloc()ed block size, part of it is used internally. */
 pool_t pool_alloconly_create(const char *name, size_t size);
-/* Like alloconly pool, but clear the memory before freeing it. The idea is
-   that you could allocate memory for storing sensitive information from this
-   pool, and be sure that it gets cleared from the memory when it's no longer
-   needed. */
-pool_t pool_alloconly_create_clean(const char *name, size_t size);
 
 /* When allocating memory from returned pool, the data stack frame must be
    the same as it was when calling this function. pool_unref() also checks