]> git.imager.perl.org - imager.git/blobdiff - error.c
- Imager::Cookbook wasn't included in the MANIFEST
[imager.git] / error.c
diff --git a/error.c b/error.c
index e350d3c5a1cdf5dbd0f95d303c370370d1e2fdb2..b1e87d38d77a10eff2d562b8990dbb114d057720 100644 (file)
--- 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
 
 /* 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. */
 /* 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;
 
 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() {
 
 =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;
 }
 
 /*
   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.
 
 
 Called by an imager function to push an error message onto the stack.
 
@@ -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;
     }
     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);
     if (!full) {
       /* just quit, at least it's on stderr */
       exit(EXIT_FAILURE);