]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
1888. [func] "USE INTERNAL MALLOC" is now runtime selectable.
authorMark Andrews <marka@isc.org>
Fri, 17 Jun 2005 02:22:45 +0000 (02:22 +0000)
committerMark Andrews <marka@isc.org>
Fri, 17 Jun 2005 02:22:45 +0000 (02:22 +0000)
                        [RT #14892]

CHANGES
bin/check/named-checkconf.c
lib/dns/dst_api.c
lib/dns/openssl_link.c
lib/dns/openssldh_link.c
lib/dns/opensslrsa_link.c
lib/isc/include/isc/mem.h
lib/isc/mem.c
lib/tests/t_api.c

diff --git a/CHANGES b/CHANGES
index b9b5c4cb9e427509c12bae7f175e6918381e8a43..92337a6ca19760962c06690ced490287f0b4a229 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
+1888.  [func]          "USE INTERNAL MALLOC" is now runtime selectable.
+                       [RT #14892]
+
 1887.  [func]          Detect duplicates of UDP queries we are recursing on
                        and drop them.  New stats category "duplicates".
-                       [RT #14892]
+                       [RT #2471]
 
 1886.  [bug]           Fix unreasonably low quantum on call to
                        dns_rbt_destroy2().  Remove unnecessay unhash_node()
index c730675d17e04ee537c602f299fc5475656ef7a6..9cda04ca49d0fbe24f2f5d5c924e888bfea0767a 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: named-checkconf.c,v 1.32 2005/05/19 04:58:59 marka Exp $ */
+/* $Id: named-checkconf.c,v 1.33 2005/06/17 02:22:43 marka Exp $ */
 
 /*! \file */
 
@@ -48,7 +48,6 @@
 #include "check-tool.h"
 
 isc_log_t *logc = NULL;
-static isc_entropy_t *ectx = NULL;
 
 #define CHECK(r)\
        do { \
index 8fe5f4d7473f46243630ef4adb3b5969958ae059..c82cd55c728cfc5b3a292a674fcf4eade33e97bf 100644 (file)
@@ -18,7 +18,7 @@
 
 /*
  * Principal Author: Brian Wellington
- * $Id: dst_api.c,v 1.3 2005/04/29 00:22:45 marka Exp $
+ * $Id: dst_api.c,v 1.4 2005/06/17 02:22:43 marka Exp $
  */
 
 /*! \file */
@@ -109,6 +109,20 @@ static isc_result_t        addsuffix(char *filename, unsigned int len,
                        return (_r);            \
        } while (0);                            \
 
+static void *
+default_memalloc(void *arg, size_t size) {
+        UNUSED(arg);
+        if (size == 0U)
+                size = 1;
+        return (malloc(size));
+}
+
+static void
+default_memfree(void *arg, void *ptr) {
+        UNUSED(arg);
+        free(ptr);
+}
+
 isc_result_t
 dst_lib_init(isc_mem_t *mctx, isc_entropy_t *ectx, unsigned int eflags) {
        isc_result_t result;
@@ -124,9 +138,12 @@ dst_lib_init(isc_mem_t *mctx, isc_entropy_t *ectx, unsigned int eflags) {
         * When using --with-openssl, there seems to be no good way of not
         * leaking memory due to the openssl error handling mechanism.
         * Avoid assertions by using a local memory context and not checking
-        * for leaks on exit.
+        * for leaks on exit.  Note: as there are leaks we cannot use
+        * ISC_MEMFLAG_INTERNAL as it will free up memory still being used
+        * by libcrypto.
         */
-       result = isc_mem_create(0, 0, &dst__memory_pool);
+       result = isc_mem_createx2(0, 0, default_memalloc, default_memfree,
+                                 NULL, &dst__memory_pool, 0);
        if (result != ISC_R_SUCCESS)
                return (result);
        isc_mem_setdestroycheck(dst__memory_pool, ISC_FALSE);
index 66af09ebbb3c8c53e2b4d42cc077e88fbff7cb0a..63b7b8674c64319cb431a00e301c25db1cdd310d 100644 (file)
@@ -18,7 +18,7 @@
 
 /*
  * Principal Author: Brian Wellington
- * $Id: openssl_link.c,v 1.3 2005/04/29 00:22:49 marka Exp $
+ * $Id: openssl_link.c,v 1.4 2005/06/17 02:22:44 marka Exp $
  */
 #ifdef OPENSSL
 
@@ -132,6 +132,11 @@ isc_result_t
 dst__openssl_init() {
        isc_result_t result;
 
+#ifdef  DNS_CRYPTO_LEAKS
+       CRYPTO_malloc_debug_init();
+       CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
+       CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
+#endif
        CRYPTO_set_mem_functions(mem_alloc, mem_realloc, mem_free);
        nlocks = CRYPTO_num_locks();
        locks = mem_alloc(sizeof(isc_mutex_t) * nlocks);
@@ -179,19 +184,45 @@ dst__openssl_init() {
 
 void
 dst__openssl_destroy() {
+
+       /*
+        * Sequence taken from apps_shutdown() in <apps/apps.h>.
+        */
+       CONF_modules_unload(1);
+       EVP_cleanup();
+#ifdef USE_ENGINE
+       ENGINE_cleanup();
+#endif
+       CRYPTO_cleanup_all_ex_data();
+       ERR_clear_error();
+       ERR_free_strings();
+       ERR_remove_state(0);
+
+#ifdef  DNS_CRYPTO_LEAKS
+       CRYPTO_mem_leaks_fp(stderr);
+#endif
+
+#if 0
+       /*
+        * The old error sequence that leaked.  Remove for 9.4.1 if
+        * there are no issues by then.
+        */
        ERR_clear_error();
 #ifdef USE_ENGINE
        if (e != NULL) {
                ENGINE_free(e);
                e = NULL;
        }
+#endif
 #endif
        if (locks != NULL) {
                DESTROYMUTEXBLOCK(locks, nlocks);
                mem_free(locks);
        }
-       if (rm != NULL)
+       if (rm != NULL) {
+               RAND_cleanup();
                mem_free(rm);
+       }
 }
 
 isc_result_t
index 7c1e50e00e1eb39cce2c7c98436c3d65a3e7c9a6..5c99f72a35ff788ce0855f6d8d6164e3742b0266 100644 (file)
@@ -18,7 +18,7 @@
 
 /*
  * Principal Author: Brian Wellington
- * $Id: openssldh_link.c,v 1.3 2005/04/29 00:22:49 marka Exp $
+ * $Id: openssldh_link.c,v 1.4 2005/06/17 02:22:44 marka Exp $
  */
 
 #ifdef OPENSSL
@@ -149,7 +149,7 @@ openssldh_generate(dst_key_t *key, int generator) {
                {
                        dh = DH_new();
                        if (dh == NULL)
-                               return (ISC_R_NOMEMORY);
+                               return (dst__openssl_toresult(ISC_R_NOMEMORY));
                        if (key->key_size == 768)
                                dh->p = &bn768;
                        else if (key->key_size == 1024)
@@ -285,7 +285,7 @@ openssldh_fromdns(dst_key_t *key, isc_buffer_t *data) {
 
        dh = DH_new();
        if (dh == NULL)
-               return (ISC_R_NOMEMORY);
+               return (dst__openssl_toresult(ISC_R_NOMEMORY));
        dh->flags &= ~DH_FLAG_CACHE_MONT_P;
 
        /*
index 85dd9af1ac642ef005efce2736e1826064879aa9..2e1f1e63d7996631378585405fe7035b9ba327d0 100644 (file)
@@ -17,7 +17,7 @@
 
 /*
  * Principal Author: Brian Wellington
- * $Id: opensslrsa_link.c,v 1.3 2005/04/29 00:22:49 marka Exp $
+ * $Id: opensslrsa_link.c,v 1.4 2005/06/17 02:22:44 marka Exp $
  */
 #ifdef OPENSSL
 
@@ -342,7 +342,7 @@ opensslrsa_fromdns(dst_key_t *key, isc_buffer_t *data) {
 
        rsa = RSA_new();
        if (rsa == NULL)
-               return (ISC_R_NOMEMORY);
+               return (dst__openssl_toresult(ISC_R_NOMEMORY));
        SET_FLAGS(rsa);
 
        if (r.length < 1) {
index 19acbd2eb0493df8151722e70b0b638136706489..9df55821398932b923a72d927a465e992427b7ad 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: mem.h,v 1.64 2005/06/10 07:00:20 marka Exp $ */
+/* $Id: mem.h,v 1.65 2005/06/17 02:22:44 marka Exp $ */
 
 #ifndef ISC_MEM_H
 #define ISC_MEM_H 1
@@ -126,10 +126,30 @@ LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_debugging;
 #define _ISC_MEM_FLARG
 #endif
 
+/*!
+ * Define ISC_MEM_USE_INTERNAL_MALLOC=1 to use the internal malloc()
+ * implementation in preference to the system one.  The internal malloc()
+ * is very space-efficient, and quite fast on uniprocessor systems.  It
+ * performs poorly on multiprocessor machines.
+ * JT: we can overcome the performance issue on multiprocessor machines
+ * by carefully separating memory contexts.
+ */
+
+#ifndef ISC_MEM_USE_INTERNAL_MALLOC
+#define ISC_MEM_USE_INTERNAL_MALLOC 1
+#endif
+
 /*
  * Flags for isc_mem_create2()calls.
  */
 #define ISC_MEMFLAG_NOLOCK     0x00000001       /* no lock is necessary */
+#define ISC_MEMFLAG_INTERNAL   0x00000002       /* use internal malloc */
+#if ISC_MEM_USE_INTERNAL_MALLOC
+#define ISC_MEMFLAG_DEFAULT    ISC_MEMFLAG_INTERNAL
+#else
+#define ISC_MEMFLAG_DEFAULT    0
+#endif
+
 
 #define isc_mem_get(c, s)      isc__mem_get((c), (s) _ISC_MEM_FILELINE)
 #define isc_mem_allocate(c, s) isc__mem_allocate((c), (s) _ISC_MEM_FILELINE)
@@ -217,13 +237,12 @@ isc_mem_createx2(size_t max_size, size_t target_size,
  * \brief Create a memory context.
  *
  * 'max_size' and 'target_size' are tuning parameters.  When
- * ISC_MEM_USE_INTERNAL_MALLOC is true, allocations smaller than
- * 'max_size' will be satisfied by getting blocks of size
- * 'target_size' from the system allocator and breaking them up into
- * pieces; larger allocations will use the system allocator directly.
- * If 'max_size' and/or 'target_size' are zero, default values will be
- * used.  When ISC_MEM_USE_INTERNAL_MALLOC is false, 'target_size' is
- * ignored.
+ * ISC_MEMFLAG_INTERNAL is set, allocations smaller than 'max_size'
+ * will be satisfied by getting blocks of size 'target_size' from the
+ * system allocator and breaking them up into pieces; larger allocations
+ * will use the system allocator directly. If 'max_size' and/or
+ * 'target_size' are zero, default values will be * used.  When
+ * ISC_MEMFLAG_INTERNAL is not set, 'target_size' is ignored.
  *
  * 'max_size' is also used to size the statistics arrays and the array
  * used to record active memory when ISC_MEM_DEBUGRECORD is set.  Settin
index f15f7317105085983f2173f27c2c032ec9e8a3c5..387a97bc94093096508d3153681c75ae8bdef65e 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: mem.c,v 1.121 2005/06/10 07:00:19 marka Exp $ */
+/* $Id: mem.c,v 1.122 2005/06/17 02:22:44 marka Exp $ */
 
 /*! \file */
 
 #endif
 LIBISC_EXTERNAL_DATA unsigned int isc_mem_debugging = ISC_MEM_DEBUGGING;
 
-/*!
- * Define ISC_MEM_USE_INTERNAL_MALLOC=1 to use the internal malloc()
- * implementation in preference to the system one.  The internal malloc()
- * is very space-efficient, and quite fast on uniprocessor systems.  It
- * performs poorly on multiprocessor machines.
- * JT: we can overcome the performance issue on multiprocessor machines
- * by carefully separating memory contexts.
- */
-#ifndef ISC_MEM_USE_INTERNAL_MALLOC
-#define ISC_MEM_USE_INTERNAL_MALLOC 1
-#endif
-
 /*
  * Constants.
  */
@@ -107,10 +95,8 @@ typedef struct {
 struct stats {
        unsigned long           gets;
        unsigned long           totalgets;
-#if ISC_MEM_USE_INTERNAL_MALLOC
        unsigned long           blocks;
        unsigned long           freefrags;
-#endif /* ISC_MEM_USE_INTERNAL_MALLOC */
 };
 
 #define MEM_MAGIC              ISC_MAGIC('M', 'e', 'm', 'C')
@@ -143,7 +129,7 @@ struct isc_mem {
        void *                  water_arg;
        ISC_LIST(isc_mempool_t) pools;
 
-#if ISC_MEM_USE_INTERNAL_MALLOC
+       /*  ISC_MEMFLAG_INTERNAL */
        size_t                  mem_target;
        element **              freelists;
        element *               basic_blocks;
@@ -152,7 +138,6 @@ struct isc_mem {
        unsigned int            basic_table_size;
        unsigned char *         lowest;
        unsigned char *         highest;
-#endif /* ISC_MEM_USE_INTERNAL_MALLOC */
 
 #if ISC_MEM_TRACKLINES
        debuglist_t *           debuglist;
@@ -318,7 +303,6 @@ delete_trace_entry(isc_mem_t *mctx, const void *ptr, unsigned int size,
 }
 #endif /* ISC_MEM_TRACKLINES */
 
-#if ISC_MEM_USE_INTERNAL_MALLOC
 static inline size_t
 rmsize(size_t size) {
        /*
@@ -598,8 +582,6 @@ mem_putunlocked(isc_mem_t *ctx, void *mem, size_t size) {
        ctx->inuse -= new_size;
 }
 
-#else /* ISC_MEM_USE_INTERNAL_MALLOC */
-
 /*!
  * Perform a malloc, doing memory filling and overrun detection as necessary.
  */
@@ -680,8 +662,6 @@ mem_putstats(isc_mem_t *ctx, void *ptr, size_t size) {
        }
 }
 
-#endif /* ISC_MEM_USE_INTERNAL_MALLOC */
-
 /*
  * Private.
  */
@@ -710,7 +690,7 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
                isc_mem_t **ctxp)
 {
        return (isc_mem_createx2(init_max_size, target_size, memalloc, memfree,
-                                arg, ctxp, 0));
+                                arg, ctxp, ISC_MEMFLAG_DEFAULT));
                                 
 }
 
@@ -728,10 +708,6 @@ isc_mem_createx2(size_t init_max_size, size_t target_size,
 
        INSIST((ALIGNMENT_SIZE & (ALIGNMENT_SIZE - 1)) == 0);
 
-#if !ISC_MEM_USE_INTERNAL_MALLOC
-       UNUSED(target_size);
-#endif
-
        ctx = (memalloc)(arg, sizeof(*ctx));
        if (ctx == NULL)
                return (ISC_R_NOMEMORY);
@@ -774,10 +750,13 @@ isc_mem_createx2(size_t init_max_size, size_t target_size,
        ctx->debuglist = NULL;
 #endif
        ISC_LIST_INIT(ctx->pools);
-
-#if ISC_MEM_USE_INTERNAL_MALLOC
        ctx->freelists = NULL;
-#endif /* ISC_MEM_USE_INTERNAL_MALLOC */
+       ctx->basic_blocks = NULL;
+       ctx->basic_table = NULL;
+       ctx->basic_table_count = 0;
+       ctx->basic_table_size = 0;
+       ctx->lowest = NULL;
+       ctx->highest = NULL;
 
        ctx->stats = (memalloc)(arg,
                                (ctx->max_size+1) * sizeof(struct stats));
@@ -787,25 +766,20 @@ isc_mem_createx2(size_t init_max_size, size_t target_size,
        }
        memset(ctx->stats, 0, (ctx->max_size + 1) * sizeof(struct stats));
 
-#if ISC_MEM_USE_INTERNAL_MALLOC
-       if (target_size == 0)
-               ctx->mem_target = DEF_MEM_TARGET;
-       else
-               ctx->mem_target = target_size;
-       ctx->freelists = (memalloc)(arg, ctx->max_size * sizeof(element *));
-       if (ctx->freelists == NULL) {
-               result = ISC_R_NOMEMORY;
-               goto error;
+       if ((flags & ISC_MEMFLAG_INTERNAL) != 0) {
+               if (target_size == 0)
+                       ctx->mem_target = DEF_MEM_TARGET;
+               else
+                       ctx->mem_target = target_size;
+               ctx->freelists = (memalloc)(arg, ctx->max_size *
+                                                sizeof(element *));
+               if (ctx->freelists == NULL) {
+                       result = ISC_R_NOMEMORY;
+                       goto error;
+               }
+               memset(ctx->freelists, 0,
+                      ctx->max_size * sizeof(element *));
        }
-       memset(ctx->freelists, 0,
-              ctx->max_size * sizeof(element *));
-       ctx->basic_blocks = NULL;
-       ctx->basic_table = NULL;
-       ctx->basic_table_count = 0;
-       ctx->basic_table_size = 0;
-       ctx->lowest = NULL;
-       ctx->highest = NULL;
-#endif /* ISC_MEM_USE_INTERNAL_MALLOC */
 
 #if ISC_MEM_TRACKLINES
        if ((isc_mem_debugging & ISC_MEM_DEBUGRECORD) != 0) {
@@ -831,10 +805,8 @@ isc_mem_createx2(size_t init_max_size, size_t target_size,
        if (ctx != NULL) {
                if (ctx->stats != NULL)
                        (memfree)(arg, ctx->stats);
-#if ISC_MEM_USE_INTERNAL_MALLOC
                if (ctx->freelists != NULL)
                        (memfree)(arg, ctx->freelists);
-#endif /* ISC_MEM_USE_INTERNAL_MALLOC */
 #if ISC_MEM_TRACKLINES
                if (ctx->debuglist != NULL)
                        (ctx->memfree)(ctx->arg, ctx->debuglist);
@@ -853,7 +825,7 @@ isc_mem_create(size_t init_max_size, size_t target_size,
 {
        return (isc_mem_createx2(init_max_size, target_size,
                                 default_memalloc, default_memfree, NULL,
-                                ctxp, 0));
+                                ctxp, ISC_MEMFLAG_DEFAULT));
 }
 
 isc_result_t
@@ -872,9 +844,7 @@ destroy(isc_mem_t *ctx) {
 
        ctx->magic = 0;
 
-#if ISC_MEM_USE_INTERNAL_MALLOC
        INSIST(ISC_LIST_EMPTY(ctx->pools));
-#endif /* ISC_MEM_USE_INTERNAL_MALLOC */
 
 #if ISC_MEM_TRACKLINES
        if (ctx->debuglist != NULL) {
@@ -913,12 +883,12 @@ destroy(isc_mem_t *ctx) {
 
        (ctx->memfree)(ctx->arg, ctx->stats);
 
-#if ISC_MEM_USE_INTERNAL_MALLOC
-       for (i = 0; i < ctx->basic_table_count; i++)
-               (ctx->memfree)(ctx->arg, ctx->basic_table[i]);
-       (ctx->memfree)(ctx->arg, ctx->freelists);
-       (ctx->memfree)(ctx->arg, ctx->basic_table);
-#endif /* ISC_MEM_USE_INTERNAL_MALLOC */
+       if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
+               for (i = 0; i < ctx->basic_table_count; i++)
+                       (ctx->memfree)(ctx->arg, ctx->basic_table[i]);
+               (ctx->memfree)(ctx->arg, ctx->freelists);
+               (ctx->memfree)(ctx->arg, ctx->basic_table);
+       }
 
        ondest = ctx->ondestroy;
 
@@ -1011,14 +981,15 @@ isc__mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size FLARG) {
 
                return;
        }
-#if ISC_MEM_USE_INTERNAL_MALLOC
-       MCTXLOCK(ctx, &ctx->lock);
-       mem_putunlocked(ctx, ptr, size);
-#else /* ISC_MEM_USE_INTERNAL_MALLOC */
-       mem_put(ctx, ptr, size);
-       MCTXLOCK(ctx, &ctx->lock);
-       mem_putstats(ctx, ptr, size);
-#endif /* ISC_MEM_USE_INTERNAL_MALLOC */
+
+       if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
+               MCTXLOCK(ctx, &ctx->lock);
+               mem_putunlocked(ctx, ptr, size);
+       } else {
+               mem_put(ctx, ptr, size);
+               MCTXLOCK(ctx, &ctx->lock);
+               mem_putstats(ctx, ptr, size);
+       }
 
        DELETE_TRACE(ctx, ptr, size, file, line);
        INSIST(ctx->references > 0);
@@ -1080,15 +1051,16 @@ isc__mem_get(isc_mem_t *ctx, size_t size FLARG) {
 
        if ((isc_mem_debugging & (ISC_MEM_DEBUGSIZE|ISC_MEM_DEBUGCTX)) != 0)
                return (isc__mem_allocate(ctx, size FLARG_PASS));
-#if ISC_MEM_USE_INTERNAL_MALLOC
-       MCTXLOCK(ctx, &ctx->lock);
-       ptr = mem_getunlocked(ctx, size);
-#else /* ISC_MEM_USE_INTERNAL_MALLOC */
-       ptr = mem_get(ctx, size);
-       MCTXLOCK(ctx, &ctx->lock);
-       if (ptr != NULL)
-               mem_getstats(ctx, size);
-#endif /* ISC_MEM_USE_INTERNAL_MALLOC */
+
+       if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
+               MCTXLOCK(ctx, &ctx->lock);
+               ptr = mem_getunlocked(ctx, size);
+       } else {
+               ptr = mem_get(ctx, size);
+               MCTXLOCK(ctx, &ctx->lock);
+               if (ptr != NULL)
+                       mem_getstats(ctx, size);
+       }
 
        ADD_TRACE(ctx, ptr, size, file, line);
        if (ctx->hi_water != 0U && !ctx->hi_called &&
@@ -1133,14 +1105,14 @@ isc__mem_put(isc_mem_t *ctx, void *ptr, size_t size FLARG)
                return;
        }
 
-#if ISC_MEM_USE_INTERNAL_MALLOC
-       MCTXLOCK(ctx, &ctx->lock);
-       mem_putunlocked(ctx, ptr, size);
-#else /* ISC_MEM_USE_INTERNAL_MALLOC */
-       mem_put(ctx, ptr, size);
-       MCTXLOCK(ctx, &ctx->lock);
-       mem_putstats(ctx, ptr, size);
-#endif /* ISC_MEM_USE_INTERNAL_MALLOC */
+       if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
+               MCTXLOCK(ctx, &ctx->lock);
+               mem_putunlocked(ctx, ptr, size);
+       } else {
+               mem_put(ctx, ptr, size);
+               MCTXLOCK(ctx, &ctx->lock);
+               mem_putstats(ctx, ptr, size);
+       }
 
        DELETE_TRACE(ctx, ptr, size, file, line);
 
@@ -1223,11 +1195,10 @@ isc_mem_stats(isc_mem_t *ctx, FILE *out) {
                fprintf(out, "%s%5lu: %11lu gets, %11lu rem",
                        (i == ctx->max_size) ? ">=" : "  ",
                        (unsigned long) i, s->totalgets, s->gets);
-#if ISC_MEM_USE_INTERNAL_MALLOC
-               if (s->blocks != 0 || s->freefrags != 0)
+               if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0 &&
+                   (s->blocks != 0 || s->freefrags != 0))
                        fprintf(out, " (%lu bl, %lu ff)",
                                s->blocks, s->freefrags);
-#endif /* ISC_MEM_USE_INTERNAL_MALLOC */
                fputc('\n', out);
        }
 
@@ -1290,11 +1261,12 @@ isc__mem_allocateunlocked(isc_mem_t *ctx, size_t size) {
        size += ALIGNMENT_SIZE;
        if ((isc_mem_debugging & ISC_MEM_DEBUGCTX) != 0)
                size += ALIGNMENT_SIZE;
-#if ISC_MEM_USE_INTERNAL_MALLOC
-       si = mem_getunlocked(ctx, size);
-#else /* ISC_MEM_USE_INTERNAL_MALLOC */
-       si = mem_get(ctx, size);
-#endif /* ISC_MEM_USE_INTERNAL_MALLOC */
+
+       if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0)
+               si = mem_getunlocked(ctx, size);
+       else
+               si = mem_get(ctx, size);
+
        if (si == NULL)
                return (NULL);
        if ((isc_mem_debugging & ISC_MEM_DEBUGCTX) != 0) {
@@ -1312,15 +1284,15 @@ isc__mem_allocate(isc_mem_t *ctx, size_t size FLARG) {
 
        REQUIRE(VALID_CONTEXT(ctx));
 
-#if ISC_MEM_USE_INTERNAL_MALLOC
-       MCTXLOCK(ctx, &ctx->lock);
-       si = isc__mem_allocateunlocked(ctx, size);
-#else /* ISC_MEM_USE_INTERNAL_MALLOC */
-       si = isc__mem_allocateunlocked(ctx, size);
-       MCTXLOCK(ctx, &ctx->lock);
-       if (si != NULL)
-               mem_getstats(ctx, si[-1].u.size);
-#endif /* ISC_MEM_USE_INTERNAL_MALLOC */
+       if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
+               MCTXLOCK(ctx, &ctx->lock);
+               si = isc__mem_allocateunlocked(ctx, size);
+       } else {
+               si = isc__mem_allocateunlocked(ctx, size);
+               MCTXLOCK(ctx, &ctx->lock);
+               if (si != NULL)
+                       mem_getstats(ctx, si[-1].u.size);
+       }
 
 #if ISC_MEM_TRACKLINES
        ADD_TRACE(ctx, si, si[-1].u.size, file, line);
@@ -1363,14 +1335,14 @@ isc__mem_free(isc_mem_t *ctx, void *ptr FLARG) {
                size = si->u.size;
        }
 
-#if ISC_MEM_USE_INTERNAL_MALLOC
-       MCTXLOCK(ctx, &ctx->lock);
-       mem_putunlocked(ctx, si, size);
-#else /* ISC_MEM_USE_INTERNAL_MALLOC */
-       mem_put(ctx, si, size);
-       MCTXLOCK(ctx, &ctx->lock);
-       mem_putstats(ctx, si, size);
-#endif /* ISC_MEM_USE_INTERNAL_MALLOC */
+       if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
+               MCTXLOCK(ctx, &ctx->lock);
+               mem_putunlocked(ctx, si, size);
+       } else {
+               mem_put(ctx, si, size);
+               MCTXLOCK(ctx, &ctx->lock);
+               mem_putstats(ctx, si, size);
+       }
 
        DELETE_TRACE(ctx, ptr, size, file, line);
 
@@ -1590,12 +1562,12 @@ isc_mempool_destroy(isc_mempool_t **mpctxp) {
                item = mpctx->items;
                mpctx->items = item->next;
 
-#if ISC_MEM_USE_INTERNAL_MALLOC
-               mem_putunlocked(mctx, item, mpctx->size);
-#else /* ISC_MEM_USE_INTERNAL_MALLOC */
-               mem_put(mctx, item, mpctx->size);
-               mem_putstats(mctx, item, mpctx->size);
-#endif /* ISC_MEM_USE_INTERNAL_MALLOC */
+               if ((mctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
+                       mem_putunlocked(mctx, item, mpctx->size);
+               } else {
+                       mem_put(mctx, item, mpctx->size);
+                       mem_putstats(mctx, item, mpctx->size);
+               }
        }
        MCTXUNLOCK(mctx, &mctx->lock);
 
@@ -1665,13 +1637,13 @@ isc__mempool_get(isc_mempool_t *mpctx FLARG) {
         */
        MCTXLOCK(mctx, &mctx->lock);
        for (i = 0; i < mpctx->fillcount; i++) {
-#if ISC_MEM_USE_INTERNAL_MALLOC
-               item = mem_getunlocked(mctx, mpctx->size);
-#else /* ISC_MEM_USE_INTERNAL_MALLOC */
-               item = mem_get(mctx, mpctx->size);
-               if (item != NULL)
-                       mem_getstats(mctx, mpctx->size);
-#endif /* ISC_MEM_USE_INTERNAL_MALLOC */
+               if ((mctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
+                       item = mem_getunlocked(mctx, mpctx->size);
+               } else {
+                       item = mem_get(mctx, mpctx->size);
+                       if (item != NULL)
+                               mem_getstats(mctx, mpctx->size);
+               }
                if (item == NULL)
                        break;
                item->next = mpctx->items;
@@ -1733,16 +1705,16 @@ isc__mempool_put(isc_mempool_t *mpctx, void *mem FLARG) {
         * If our free list is full, return this to the mctx directly.
         */
        if (mpctx->freecount >= mpctx->freemax) {
-#if ISC_MEM_USE_INTERNAL_MALLOC
-               MCTXLOCK(mctx, &mctx->lock);
-               mem_putunlocked(mctx, mem, mpctx->size);
-               MCTXUNLOCK(mctx, &mctx->lock);
-#else /* ISC_MEM_USE_INTERNAL_MALLOC */
-               mem_put(mctx, mem, mpctx->size);
-               MCTXLOCK(mctx, &mctx->lock);
-               mem_putstats(mctx, mem, mpctx->size);
-               MCTXUNLOCK(mctx, &mctx->lock);
-#endif /* ISC_MEM_USE_INTERNAL_MALLOC */
+               if ((mctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
+                       MCTXLOCK(mctx, &mctx->lock);
+                       mem_putunlocked(mctx, mem, mpctx->size);
+                       MCTXUNLOCK(mctx, &mctx->lock);
+               } else {
+                       mem_put(mctx, mem, mpctx->size);
+                       MCTXLOCK(mctx, &mctx->lock);
+                       mem_putstats(mctx, mem, mpctx->size);
+                       MCTXUNLOCK(mctx, &mctx->lock);
+               }
                if (mpctx->lock != NULL)
                        UNLOCK(mpctx->lock);
                return;
index 9321dc88a0df11f259ceed377e8415f2d36a4ca1..35f7bb79fc9ae9eda164f8e9aeec1e7b24ce5ecf 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: t_api.c,v 1.56 2005/04/29 00:24:12 marka Exp $ */
+/* $Id: t_api.c,v 1.57 2005/06/17 02:22:45 marka Exp $ */
 
 /*! \file */
 
@@ -37,6 +37,7 @@
 #include <isc/commandline.h>
 #include <isc/print.h>
 #include <isc/string.h>
+#include <isc/mem.h>
 
 #include <dns/compress.h>
 #include <dns/result.h>
@@ -121,6 +122,7 @@ main(int argc, char **argv) {
        testspec_t              *pts;
        struct sigaction        sa;
 
+       isc_mem_debugging = ISC_MEM_DEBUGRECORD;
        first = ISC_TRUE;
        subprocs = 1;
        T_timeout = T_TCTOUT;