From d5837ba8c275b75388815a3263dae97cf306161b Mon Sep 17 00:00:00 2001 From: Tilghman Lesher Date: Tue, 14 Oct 2008 22:38:06 +0000 Subject: Add additional memory debugging to several core APIs, and fix several memory leaks found with these changes. (Closes issue #13505, closes issue #13543) Reported by: mav3rick, triccyx Patches: 20081001__bug13505.diff.txt uploaded by Corydon76 (license 14) Tested by: mav3rick, triccyx git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@149199 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/hashtab.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'main/hashtab.c') diff --git a/main/hashtab.c b/main/hashtab.c index a6fac4e53..d60a78a0e 100644 --- a/main/hashtab.c +++ b/main/hashtab.c @@ -209,22 +209,40 @@ unsigned int ast_hashtab_hash_short(const short x) return x; } -struct ast_hashtab *ast_hashtab_create(int initial_buckets, +struct ast_hashtab * +#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +_ast_hashtab_create +#else +ast_hashtab_create +#endif +(int initial_buckets, int (*compare)(const void *a, const void *b), int (*resize)(struct ast_hashtab *), int (*newsize)(struct ast_hashtab *tab), unsigned int (*hash)(const void *obj), - int do_locking) + int do_locking +#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) + , const char *file, int lineno, const char *function +#endif +) { struct ast_hashtab *ht; - + +#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) + if (!(ht = __ast_calloc(1, sizeof(*ht), file, lineno, function))) +#else if (!(ht = ast_calloc(1, sizeof(*ht)))) +#endif return NULL; while (!ast_is_prime(initial_buckets)) /* make sure this is prime */ initial_buckets++; +#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) + if (!(ht->array = __ast_calloc(initial_buckets, sizeof(*(ht->array)), file, lineno, function))) { +#else if (!(ht->array = ast_calloc(initial_buckets, sizeof(*(ht->array))))) { +#endif free(ht); return NULL; } -- cgit v1.2.3