From: wessels <> Date: Fri, 12 Jul 1996 23:38:11 +0000 (+0000) Subject: -fix XMALLOC_DEBUG X-Git-Tag: SQUID_3_0_PRE1~6074 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=68b468e5a592ede2f4bafa6d37ed72b4fed76d88;p=thirdparty%2Fsquid.git -fix XMALLOC_DEBUG -add XMALLOC_COUNT --- diff --git a/lib/util.c b/lib/util.c index 7f4c3c9e2b..4a509d748b 100644 --- a/lib/util.c +++ b/lib/util.c @@ -1,5 +1,5 @@ /* - * $Id: util.c,v 1.8 1996/07/09 03:41:14 wessels Exp $ + * $Id: util.c,v 1.9 1996/07/12 17:38:11 wessels Exp $ * * DEBUG: * AUTHOR: Harvest Derived @@ -171,8 +171,8 @@ void malloc_statistics(func, data) #if XMALLOC_DEBUG -#define DBG_ARRY_SZ (2<<8) -#define DBG_ARRY_BKTS (2<<8) +#define DBG_ARRY_SZ (1<<10) +#define DBG_ARRY_BKTS (1<<8) static void *malloc_ptrs[DBG_ARRY_BKTS][DBG_ARRY_SZ]; static int malloc_size[DBG_ARRY_BKTS][DBG_ARRY_SZ]; static int dbg_initd = 0; @@ -183,7 +183,7 @@ static void *Q; static void check_init() { - for (B = 0; B < DBG_ARRY_SZ; B++) { + for (B = 0; B < DBG_ARRY_BKTS; B++) { for (I = 0; I < DBG_ARRY_SZ; I++) { malloc_ptrs[B][I] = NULL; malloc_size[B][I] = 0; @@ -238,6 +238,24 @@ static void check_malloc(p, sz) } #endif +#ifdef XMALLOC_COUNT +static void xmalloc_count(p, sign) + void *p; + int sign; +{ + size_t sz; + static size_t total = 0; + int memoryAccounted(); + int mallinfoTotal(); + sz = mallocblksize(p) * sign; + total += sz; + fprintf(stderr, "xmalloc_count=%9d accounted=%9d mallinfo=%9d\n", + (int) total, + memoryAccounted(), + mallinfoTotal()); +} +#endif /* XMALLOC_COUNT */ + /* * xmalloc() - same as malloc(3). Used for portability. * Never returns NULL; fatal on error. @@ -264,6 +282,9 @@ void *xmalloc(sz) #endif #if XMALLOC_STATISTICS malloc_stat(sz); +#endif +#if XMALLOC_COUNT + xmalloc_count(p, 1); #endif return (p); } @@ -276,6 +297,9 @@ void xfree(s) { #if XMALLOC_DEBUG check_free(s); +#endif +#if XMALLOC_COUNT + xmalloc_count(s, -1); #endif if (s != NULL) free(s); @@ -287,6 +311,9 @@ void xxfree(s) { #if XMALLOC_DEBUG check_free(s); +#endif +#if XMALLOC_COUNT + xmalloc_count(s, -1); #endif free(s); } @@ -301,6 +328,10 @@ void *xrealloc(s, sz) { static void *p; +#if XMALLOC_COUNT + xmalloc_count(s, -1); +#endif + if (sz < 1) sz = 1; if ((p = realloc(s, sz)) == NULL) { @@ -318,6 +349,9 @@ void *xrealloc(s, sz) #endif #if XMALLOC_STATISTICS malloc_stat(sz); +#endif +#if XMALLOC_COUNT + xmalloc_count(p, 1); #endif return (p); } @@ -351,6 +385,9 @@ void *xcalloc(n, sz) #endif #if XMALLOC_STATISTICS malloc_stat(sz); +#endif +#if XMALLOC_COUNT + xmalloc_count(p, 1); #endif return (p); }