Explorar o código

sys_alloc() has to set headers in case it is called by initialize_allocator(). Modified also custom_malloc() to conform with this.

Ioannis Koutras %!s(int64=13) %!d(string=hai) anos
pai
achega
873e85f9f1
Modificáronse 2 ficheiros con 37 adicións e 10 borrados
  1. 18 10
      src/custom_malloc.c
  2. 19 0
      src/sys_alloc.c

+ 18 - 10
src/custom_malloc.c

@@ -76,21 +76,29 @@ void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
         }
     }
 
-    if(ptr == NULL) {
-        ptr = sys_alloc(allocator, heap, size);
-    }
+    if(ptr != NULL) {
 
-    set_requested_size(ptr, size);
-    set_next(ptr, heap->used_blocks_head);
+        /* FIXME To be refactored - START */
+        set_requested_size(ptr, size);
+        mark_used(ptr);
 
-    heap->used_blocks_head = ptr;
+        // Update the used blocks list
+        set_next(ptr, heap->used_blocks_head);
+        heap->used_blocks_head = ptr;
 
-    // Begin of Stats
+        // Begin of Stats
 
-    heap->dmm_stats.live_objects += 1;
-    heap->dmm_stats.num_malloc += 1;
+        heap->dmm_stats.live_objects += 1;
+        heap->dmm_stats.num_malloc += 1;
 
-    // End of Stats
+        // End of Stats
+        /* FIXME To be refactored - END */
+
+    }
+
+    if(ptr == NULL) {
+        ptr = sys_alloc(allocator, heap, size);
+    }
 
     // Refresh the state of the heap allocator if a certain number of
     // malloc's has been served already

+ 19 - 0
src/sys_alloc.c

@@ -63,6 +63,25 @@ void *sys_alloc(allocator_t *allocator, heap_t *heap, size_t size) {
     heap->dmm_stats.mem_allocated += req_padding(size);
     heap->dmm_stats.mem_requested += size;
 
+
+    /* FIXME To be refactored - START */
+    set_requested_size(ptr, size);
+    mark_used(ptr);
+
+    // Update the used blocks list
+    set_next(ptr, heap->used_blocks_head);
+    heap->used_blocks_head = ptr;
+
+    // Begin of Stats
+
+    heap->dmm_stats.live_objects += 1;
+    heap->dmm_stats.num_malloc += 1;
+
+    // End of Stats
+
+    /* FIXME To be refactored - END */
+
+
 #ifdef HAVE_LOCKS
     sbrk_unlock();
 #endif /* HAVE_LOCKS */