X-Git-Url: http://git.imager.perl.org/imager.git/blobdiff_plain/c5cf76149d2325d53cc92434f8478a8db2509b39..58cf0dc0212e64dd3bb3babb3c0d26924cbd92b1:/error.c diff --git a/error.c b/error.c index 0edce898..b1e87d38 100644 --- a/error.c +++ b/error.c @@ -67,13 +67,13 @@ C). The Perl level won't use all of this. /* we never actually use the last item - it's the NULL terminator */ #define ERRSTK 20 -i_errmsg error_stack[ERRSTK]; -int error_sp = ERRSTK - 1; +static i_errmsg error_stack[ERRSTK]; +static int error_sp = ERRSTK - 1; /* we track the amount of space used each string, so we don't reallocate space unless we need to. This also means that a memory tracking library may see the memory allocated for this as a leak. */ -int error_space[ERRSTK]; +static int error_space[ERRSTK]; static i_error_cb error_cb; static i_failed_cb failed_cb; @@ -186,11 +186,22 @@ Called by any imager function before doing any other processing. =cut */ void i_clear_error() { +#ifdef IMAGER_DEBUG_MALLOC + int i; + + for (i = 0; i < ERRSTK; ++i) { + if (error_space[i]) { + myfree(error_stack[i].msg); + error_stack[i].msg = NULL; + error_space[i] = 0; + } + } +#endif error_sp = ERRSTK-1; } /* -=item i_push_error(char const *msg) +=item i_push_error(int code, char const *msg) Called by an imager function to push an error message onto the stack. @@ -288,7 +299,7 @@ int i_failed(int code, char const *msg) { fputs("error:\n", stderr); sp = error_sp; while (error_stack[sp].msg) { - fprintf(stderr, " %s\n", error_stack[sp]); + fprintf(stderr, " %s\n", error_stack[sp].msg); ++sp; } /* we want to log the error too, build an error message to hand to @@ -297,7 +308,7 @@ int i_failed(int code, char const *msg) { for (sp = error_sp; error_stack[sp].msg; ++sp) { total += strlen(error_stack[sp].msg) + 2; } - full = malloc(total); + full = mymalloc(total); if (!full) { /* just quit, at least it's on stderr */ exit(EXIT_FAILURE);