Browse Source

Fixed a bug involving self-referential insertion

tree_alloc
Thomas Johnson 1 year ago
parent
commit
754f45199b
  1. 1
      main.c
  2. 10
      tree_alloc.c

1
main.c

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

10
tree_alloc.c

@ -302,8 +302,8 @@ void insert_singleton(TreeAlloc **root_ptr, TreeAlloc *to_insert) {
void insert_right(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* after) {
if (after->right != NULL) {
after->right = to_insert;
to_insert->parent = after;
after->right->parent = to_insert;
to_insert->right = after->right;
}
after->right = to_insert;
to_insert->parent = after;
@ -312,8 +312,8 @@ void insert_right(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* after)
void insert_left(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* before) {
if (before->left != NULL) {
before->left = to_insert;
to_insert->parent = before;
before->left->parent = to_insert;
to_insert->left = before->left;
}
before->left = to_insert;
to_insert->parent = before;
@ -343,7 +343,7 @@ int add_new_region(Arena *arena, uintptr_t size, uintptr_t padding, uintptr_t al
while (head->right != NULL) {
head = head->right;
}
insert_right((TreeAlloc**) arena->root_freespace, (TreeAlloc*) newreg, (TreeAlloc*) newreg);
insert_right((TreeAlloc**) arena->root_freespace, (TreeAlloc*) newreg, (TreeAlloc*) head);
#ifdef DEBUG
printf("= POST-REGION-CREATION =\n");
printf("==== FREESPACE TREE ====\n");

Loading…
Cancel
Save