Browse Source

Fixed major bug in push_block.

Ioannis Koutras 13 years ago
parent
commit
8929219116

+ 3 - 3
private-include/linked_lists/linked_lists.h

@@ -94,10 +94,10 @@ void * get_previous(void *ptr);
 /**
  * Push a memory block to the head of a linked list.
  * 
- * \param *block The block to be put.
- * \param *starting_node The starting memory block of the list.
+ * \param **block A pointer to the block to be put.
+ * \param **starting_node A pointer to the starting memory block of the list.
  */
-void push_block(void *block, void *starting_node);
+void push_block(void **block, void **starting_node);
 
 /**
  * Removes a memory block from a linked list of memory blocks.

+ 3 - 3
src/custom_free.c

@@ -104,7 +104,7 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
                 current_maptable_node = current_maptable_node->next;
             }
         }
-        push_block(ptr, current_maptable_node->fixed_list_head);
+        push_block(&ptr, &current_maptable_node->fixed_list_head);
     } else { /* put it in the free list */
 #endif /* WITH_FIXED_LISTS */
 #if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
@@ -112,10 +112,10 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
          * coalesced
          */
         if(!coalesced) {
-            push_block(ptr, heap->free_list_head);
+            push_block(&ptr, &heap->free_list_head);
         }
 #else
-        push_block(ptr, heap->free_list_head);
+        push_block(&ptr, &heap->free_list_head);
 #endif /* COALESCING_FIXED || COALESCING_VARIABLE */
 #ifdef WITH_FIXED_LISTS
     }

+ 1 - 1
src/custom_malloc.c

@@ -103,7 +103,7 @@ void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
 #endif /* (SPLITTING_FIXED) || (SPLITTING_VARIABLE) */
 
         /* Update the used blocks list */
-        push_block(ptr, heap->used_blocks_head);
+        push_block(&ptr, &heap->used_blocks_head);
 
 #ifdef WITH_STATS
         /* Update statistics */

+ 10 - 5
src/linked_lists/linked_lists.c

@@ -40,13 +40,18 @@ void * get_previous(void *ptr) {
 
 #endif /* BLOCKS_IN_DLL */
 
-void push_block(void *block, void *starting_node) {
+void push_block(void **block, void **starting_node) {
+    if(*starting_node != NULL) {
 #ifdef BLOCKS_IN_DLL
-    set_previous(starting_node, block);
-    set_previous(block, NULL);
+        set_previous(*starting_node, *block);
 #endif /* BLOCKS_IN_DLL */
-    set_next(block, starting_node);
-    starting_node = block;
+        set_next(*starting_node, *block);
+    }
+#ifdef BLOCKS_IN_DLL
+    set_previous(*block, NULL);
+#endif /* BLOCKS_IN_DLL */
+    set_next(*block, NULL);
+    *starting_node = *block;
 }
 
 #ifdef BLOCKS_IN_SLL

+ 2 - 2
src/split.c

@@ -51,10 +51,10 @@ void split(allocator_t *allocator, heap_t *heap, void *ptr,
                 current_maptable_node = current_maptable_node->next;
             }
         }
-        push_block(new_block, current_maptable_node->fixed_list_head);
+        push_block(&new_block, &current_maptable_node->fixed_list_head);
     } else { /* put it in the free list */
 #endif /* WITH_FIXED_LISTS */
-        push_block(new_block, heap->free_list_head);
+        push_block(&new_block, &heap->free_list_head);
 #ifdef WITH_FIXED_LISTS
     }
 #endif /* WITH_FIXED_LISTS */

+ 1 - 1
src/sys_alloc.c

@@ -113,7 +113,7 @@ void *sys_alloc(allocator_t *allocator, heap_t *heap, size_t size) {
 #endif /* FUTURE_FEATURES */
 
     /* Update the used blocks list */
-    push_block(ptr, heap->used_blocks_head);
+    push_block(&ptr, &heap->used_blocks_head);
 
 #ifdef WITH_STATS
     /* Update statistics */