]> git.imager.perl.org - imager.git/commitdiff
[rt #70388] debug mymalloc() no longer builds a string, just stores the pointer
authorTony Cook <tony@develop-help.com>
Sat, 10 Mar 2012 03:13:26 +0000 (14:13 +1100)
committerTony Cook <tony@develop-help.com>
Sat, 10 Mar 2012 03:13:26 +0000 (14:13 +1100)
The debug malloc() code would use snprintf() (or even worse,
sprintf()) to build a string to track when the memory allocation was
performed for later tracking.

Now we just store the pointers, which should come from __FILE__ and
hence be static.

Changes
io.c

diff --git a/Changes b/Changes
index 8087847b3f68315d5f875154d3080e848b4337aa..48b486ccaaa37683a54aead205d63afb4f33c24f 100644 (file)
--- a/Changes
+++ b/Changes
@@ -13,6 +13,11 @@ Imager release history.  Older releases can be found in Changes.old
    For the bundled modules this could hide useful error messages.
    https://rt.cpan.org/Ticket/Display.html?id=75560
 
+ - IM_DEBUG_MALLOC mymalloc() no longer sn?printfs() a string to a
+   buffer in the array of allocations, but just stores the filename
+   pointer and line number.
+   https://rt.cpan.org/Ticket/Display.html?id=70388
+
 Imager 0.88 - 22 Feb 2012
 ===========
 
diff --git a/io.c b/io.c
index 4e78cd78f20b4fdbc8e9d9dbd64735610805f669..3d8c4534c991f86d6085bf26a038a4a4785e417d 100644 (file)
--- a/io.c
+++ b/io.c
@@ -25,7 +25,8 @@ static int malloc_need_init = 1;
 typedef struct {
   void* ptr;
   size_t size;
-  char comm[MAXDESC];
+  const char *file;
+  int line;
 } malloc_entry;
 
 malloc_entry malloc_pointers[MAXMAL];
@@ -69,12 +70,8 @@ set_entry(int i, char *buf, size_t size, char *file, int line) {
   buf += UNDRRNVAL;
   malloc_pointers[i].ptr  = buf;
   malloc_pointers[i].size = size;
-#ifdef IMAGER_SNPRINTF
-  snprintf(malloc_pointers[i].comm, sizeof(malloc_pointers[i].comm), 
-          "%s (%d)", file, line);
-#else
-  sprintf(malloc_pointers[i].comm,"%s (%d)", file, line);
-#endif
+  malloc_pointers[i].file = file;
+  malloc_pointers[i].line = line;
   return buf;
 }
 
@@ -87,7 +84,7 @@ malloc_state(void) {
   mm_log((0,"malloc_state()\n"));
   bndcheck_all();
   for(i=0; i<MAXMAL; i++) if (malloc_pointers[i].ptr != NULL) {
-      mm_log((0,"%d: %lu (%p) : %s\n", i, (unsigned long)malloc_pointers[i].size, malloc_pointers[i].ptr, malloc_pointers[i].comm));
+      mm_log((0,"%d: %lu (%p) : %s (%d)\n", i, (unsigned long)malloc_pointers[i].size, malloc_pointers[i].ptr, malloc_pointers[i].file, malloc_pointers[i].line));
     total += malloc_pointers[i].size;
   }
   if (total == 0) mm_log((0,"No memory currently used!\n"))
@@ -205,7 +202,7 @@ myfree_file_line(void *p, char *file, int line) {
     return;
   
   for(i=0; i<MAXMAL; i++) if (malloc_pointers[i].ptr == p) {
-    mm_log((1,"myfree_file_line: pointer %i (%s) freed at %s (%i)\n", i, malloc_pointers[i].comm, file, line));
+      mm_log((1,"myfree_file_line: pointer %i (%s (%d)) freed at %s (%i)\n", i, malloc_pointers[i].file, malloc_pointers[i].line, file, line));
     bndcheck(i);
     malloc_pointers[i].ptr = NULL;
     match++;