summaryrefslogtreecommitdiff
path: root/src/library/gc/shm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/library/gc/shm.c')
-rw-r--r--src/library/gc/shm.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/library/gc/shm.c b/src/library/gc/shm.c
index 8077352..7f8609a 100644
--- a/src/library/gc/shm.c
+++ b/src/library/gc/shm.c
@@ -28,7 +28,7 @@ void* shm_alloc(size_t size) {
//go through all blocks, get the one with the closest size
struct shm_block *i = blocks, *block = 0;
while (i) {
- if (i->size >= size && i->is_hole == 1 && i->size < block->size) block = i;
+ if (i->size >= size && i->is_hole == 1 && (block == 0 || i->size < block->size)) block = i;
i = i->next;
}
if (block == 0) {
@@ -57,7 +57,7 @@ static void unify (struct shm_block *b) {
if (b->next == 0 || b->is_hole == 0 || b->next->is_hole == 0) return;
struct shm_block *n = b->next;
b->size += n->size;
- n->next->prev = b;
+ if (n->next != 0) n->next->prev = b;
b->next = n->next;
free(n);
}