[asterisk-commits] tilghman: branch tilghman/malloc_hold r209449 - /team/tilghman/malloc_hold/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 29 01:55:28 CDT 2009


Author: tilghman
Date: Wed Jul 29 01:55:25 2009
New Revision: 209449

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=209449
Log:
Fixup defines, such that MALLOC_DEBUG will compile independently of MALLOC_HOLD

Modified:
    team/tilghman/malloc_hold/main/astmm.c

Modified: team/tilghman/malloc_hold/main/astmm.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/tilghman/malloc_hold/main/astmm.c?view=diff&rev=209449&r1=209448&r2=209449
==============================================================================
--- team/tilghman/malloc_hold/main/astmm.c (original)
+++ team/tilghman/malloc_hold/main/astmm.c Wed Jul 29 01:55:25 2009
@@ -33,9 +33,9 @@
 #include <string.h>
 #include <stddef.h>
 #include <time.h>
+#ifdef MALLOC_HOLD
 #include <sys/mman.h>
 #include <signal.h>
-#ifdef MALLOC_HOLD
 #include <malloc.h>
 #include <errno.h>
 #endif /* MALLOC_HOLD */
@@ -46,18 +46,15 @@
 #include "asterisk/lock.h"
 #include "asterisk/strings.h"
 #include "asterisk/unaligned.h"
-#if ((defined(AST_DEVMODE)) && (defined(linux)))
-#include <execinfo.h>
-#endif
 
 #define SOME_PRIME 563
+
+#ifdef MALLOC_HOLD
 #define FREE_LIST SOME_PRIME
 #define POLLUTED_LIST SOME_PRIME + 1
 #define AVAILABLE_LIST SOME_PRIME + 2
 
-#ifdef MALLOC_HOLD
 #define HOLD_LENGTH 90
-#endif
 
 /* Cannot include utils.h, as it defines things that this file implements,
  * but could eventually put these defines in a separate header file. */
@@ -86,8 +83,7 @@
 	FUNC_STRDUP,
 	FUNC_STRNDUP,
 	FUNC_VASPRINTF,
-	FUNC_ASPRINTF,
-	FUNC_FREE,
+	FUNC_ASPRINTF
 };
 
 /* Undefine all our macros */
@@ -393,14 +389,16 @@
 	}
 	ast_mutex_unlock(&reglock);
 }
+#endif
 
 static inline void *__ast_alloc_region(size_t size, const enum func_type which, const char *file, int lineno, const char *func, unsigned int cache)
 {
-	struct ast_region *reg = NULL, *prev = NULL, *best_prev = NULL, *best_reg = NULL;
+	struct ast_region *reg = NULL;
 	void *ptr = NULL;
 	unsigned int *fence;
 	int hash;
 #ifdef MALLOC_HOLD
+	struct ast_region *prev = NULL, *best_prev = NULL, *best_reg = NULL;
 	size_t fullsize = size + sizeof(*reg) + sizeof(*fence);
 
 	if (pagesize == -1 && (pagesize = sysconf(_SC_PAGESIZE)) == -1) {
@@ -472,7 +470,9 @@
 	ast_copy_string(reg->alloc_func, func, sizeof(reg->alloc_func));
 	reg->alloc_lineno = lineno;
 	reg->len = size;
+#ifdef MALLOC_HOLD
 	reg->fullsize = fullsize;
+#endif
 	reg->which = which;
 	reg->cache = cache;
 	ptr = reg->data;
@@ -507,13 +507,7 @@
 	return len;
 }
 
-#ifdef MALLOC_HOLD
-/* Not strictly necessary to make this a global symbol, but it helps when debugging */
-void __ast_free_region(void *ptr, const char *file, int lineno, const char *func);
-#else
-static
-#endif
-void __ast_free_region(void *ptr, const char *file, int lineno, const char *func)
+static void __ast_free_region(void *ptr, const char *file, int lineno, const char *func)
 {
 	int hash;
 	struct ast_region *reg, *prev = NULL;
@@ -941,7 +935,13 @@
 
 #ifdef MALLOC_HOLD
 static char memory_show_free_available_help[] =
-"Usage: memory show {free|available|polluted}\n";
+"Usage: memory show {free|available|polluted}\n"
+"       Show memory pools in each of several states:\n"
+"       free      - Freed by threads, but held for a period of time before being\n"
+"                   made available for reuse.\n"
+"       available - Available for reallocation by another thread.\n"
+"       polluted  - Used while in a 'free' state, and thus won't be released for\n"
+"                   reuse.\n";
 #endif
 
 static struct ast_cli_entry cli_show_memory_allocations_deprecated = {




More information about the asterisk-commits mailing list