Browse Source

Track big blocks too if WITH_DEBUG is enabled

Ioannis Koutras 12 years ago
parent
commit
7838c68d22
3 changed files with 27 additions and 0 deletions
  1. 3 0
      include/dmmlib/allocator.h
  2. 12 0
      src/debug.c
  3. 12 0
      src/malloc.c

+ 3 - 0
include/dmmlib/allocator.h

@@ -38,6 +38,9 @@
 /** The allocator structure of dmmlib. */
 typedef struct allocator_s {
     raw_block_header_t *raw_block_head; /**< The head of the raw blocks list. */
+#ifdef WITH_DEBUG
+    raw_block_header_t *big_blocks_head; /**< The head of the big blocks list. */
+#endif /* WITH_DEBUG */
 #ifdef HAVE_LOCKS
     pthread_mutex_t creation_mutex; /**< Mutex to allow the creation of new raw
                                       blocks. */

+ 12 - 0
src/debug.c

@@ -49,6 +49,18 @@ void get_raw_blocks(allocator_t *allocator) {
 
     TRACE_3("dmmlib - there are %d raw blocks\n", counter);
 
+    current_raw_block = allocator->big_blocks_head;
+    counter = 0;
+
+    while(current_raw_block) {
+        counter++;
+        TRACE_3("dmmlib - Raw block at %p of size %zu\n",
+                (void *)current_raw_block,
+                current_raw_block->size);
+        current_raw_block = current_raw_block->next_raw_block;
+    }
+
+    TRACE_3("dmmlib - there are %d big blocks\n", counter);
 }
 
 /** Tries to find the raw block owner of a memory allocation.

+ 12 - 0
src/malloc.c

@@ -109,6 +109,18 @@ void * malloc(size_t size) {
                     sizeof(raw_block_header_t), BIGBLOCK);
             if(ptr != NULL) {
 
+#ifdef WITH_DEBUG
+#ifdef HAVE_LOCKS
+                pthread_mutex_lock(&systemallocator.creation_mutex);
+#endif /* HAVE_LOCKS */
+                ((raw_block_header_t *)ptr)->next_raw_block = 
+                    systemallocator.big_blocks_head;
+                systemallocator.big_blocks_head = (raw_block_header_t *)ptr;
+#ifdef HAVE_LOCKS
+                pthread_mutex_unlock(&systemallocator.creation_mutex);
+#endif /* HAVE_LOCKS */
+#endif /* WITH_DEBUG */
+
 #ifdef WITH_ALLOCATOR_STATS
                 update_stats(&systemallocator.dmm_stats,
                         MALLOC,