X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcutil%2Fstacktrace.c;h=9f335e44258dffe481751c37de03a3fb05a2a61d;hb=52e57c880aba9c5e89f59d962eb9af75670b76e0;hp=eb8f2458e1b468965243cd5206a1f4def588fa72;hpb=e2c551b9693b6d42e5997b9df416a17fb94c1ccb;p=silc.git diff --git a/lib/silcutil/stacktrace.c b/lib/silcutil/stacktrace.c index eb8f2458..9f335e44 100644 --- a/lib/silcutil/stacktrace.c +++ b/lib/silcutil/stacktrace.c @@ -1,10 +1,10 @@ /* - stacktrace.c + stacktrace.c Author: Pekka Riikonen - Copyright (C) 2002 Pekka Riikonen + Copyright (C) 2002, 2007 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,15 +17,20 @@ */ -#include "silcincludes.h" +#include "silc.h" #ifdef SILC_STACKTRACE static void *st_blocks = NULL; static unsigned long st_blocks_count = 0; -static int dump = FALSE; +static SilcBool dump = FALSE; +static SilcBool malloc_check = FALSE; -#define SILC_ST_DEPTH 10 +#ifdef SILC_DEBUG +#define SILC_ST_DEPTH 15 +#else +#define SILC_ST_DEPTH 8 +#endif /* SILC_DEBUG */ /* Memory block with stack trace */ typedef struct SilcStBlockStruct { @@ -62,6 +67,16 @@ void silc_st_stacktrace(SilcStBlock stack) dump = TRUE; } + if (!malloc_check) { + /* Linux libc malloc check */ + setenv("MALLOC_CHECK_", "2", 1); + + /* NetBSD malloc check */ + setenv("MALLOC_OPTIONS", "AJ", 1); + + malloc_check = TRUE; + } + /* Save the stack */ SILC_ST_GET_FP(fp); for (stack->depth = 0; fp; stack->depth++) { @@ -137,6 +152,8 @@ void silc_st_free(void *ptr, const char *file, int line) st_blocks = stack->next; st_blocks_count--; + + memset(stack, 'F', SILC_ST_GET_SIZE(stack->size)); free(stack); } @@ -180,7 +197,7 @@ void silc_st_dump(void) for (s = stack; s; s = s->next) { if (s->file == stack->file && s->line == stack->line && s->depth == stack->depth && - !memcmp(s->stack, stack->stack, + !memcmp(s->stack, stack->stack, (s->depth * sizeof(stack->stack[0])))) { blocks++; bytes += s->size; @@ -192,14 +209,14 @@ void silc_st_dump(void) fprintf(fp, "%s:%d: #blocks=%lu, bytes=%lu\n", stack->file, stack->line, blocks, bytes); for (i = 0; i < stack->depth; i++) - fprintf(fp, "%p\n", stack->stack[i]); + fprintf(fp, "\tpc=%p\n", stack->stack[i]); } } if (!leaks) { fprintf(stderr, "\nNo memory leaks\n"); } else { - fprintf(stderr, + fprintf(stderr, "-----------------------------------------\n" "-----------------------------------------\n" " Memory leaks dumped to 'stacktrace.log'\n"