Browse Source

Fixed a bug involving self-referential insertion

Thomas Johnson 5 months ago
parent
commit
754f45199b
2 changed files with 5 additions and 6 deletions
  1. 0
    1
      main.c
  2. 5
    5
      tree_alloc.c

+ 0
- 1
main.c View File

@@ -77,7 +77,6 @@ void new_region(struct AllocationRecord *dummy, struct Arena *arena) {
77 77
     return;
78 78
   }
79 79
   for (int ii = 0; ii < size; ii++) {
80
-    printf("writing %p\n", ((void*) region) + ii);
81 80
     ((char*) region)[ii] = (char) rand();
82 81
   }
83 82
   insert_record(dummy, region, size);

+ 5
- 5
tree_alloc.c View File

@@ -302,8 +302,8 @@ void insert_singleton(TreeAlloc **root_ptr, TreeAlloc *to_insert) {
302 302
 
303 303
 void insert_right(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* after) {
304 304
   if (after->right != NULL) {
305
-    after->right = to_insert;
306
-    to_insert->parent = after;
305
+    after->right->parent = to_insert;
306
+    to_insert->right = after->right;
307 307
   }
308 308
   after->right = to_insert;
309 309
   to_insert->parent = after;
@@ -312,8 +312,8 @@ void insert_right(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* after)
312 312
 
313 313
 void insert_left(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* before) {
314 314
   if (before->left != NULL) {
315
-    before->left = to_insert;
316
-    to_insert->parent = before;
315
+    before->left->parent = to_insert;
316
+    to_insert->left = before->left;
317 317
   }
318 318
   before->left = to_insert;
319 319
   to_insert->parent = before;
@@ -343,7 +343,7 @@ int add_new_region(Arena *arena, uintptr_t size, uintptr_t padding, uintptr_t al
343 343
       while (head->right != NULL) {
344 344
         head = head->right;
345 345
       }
346
-      insert_right((TreeAlloc**) arena->root_freespace, (TreeAlloc*) newreg, (TreeAlloc*) newreg);
346
+      insert_right((TreeAlloc**) arena->root_freespace, (TreeAlloc*) newreg, (TreeAlloc*) head);
347 347
 #ifdef DEBUG
348 348
       printf("= POST-REGION-CREATION =\n");
349 349
       printf("==== FREESPACE TREE ====\n");

Loading…
Cancel
Save