forked from Bananymous/banan-os
LibC: Fix a bug in malloc
You could not allocate with size equal to one of the pool sizes.
This commit is contained in:
parent
a66c3bdae5
commit
49d941ad65
|
@ -123,7 +123,7 @@ void* malloc(size_t size)
|
||||||
|
|
||||||
// find the first pool with size atleast size
|
// find the first pool with size atleast size
|
||||||
size_t first_usable_pool = 0;
|
size_t first_usable_pool = 0;
|
||||||
while (s_malloc_pools[first_usable_pool].size < size)
|
while (s_malloc_pools[first_usable_pool].size - sizeof(malloc_node_t) < size)
|
||||||
first_usable_pool++;
|
first_usable_pool++;
|
||||||
// first_usable_pool = ceil(log(size/s_malloc_smallest_pool, s_malloc_pool_size_mult))
|
// first_usable_pool = ceil(log(size/s_malloc_smallest_pool, s_malloc_pool_size_mult))
|
||||||
|
|
||||||
|
@ -140,6 +140,7 @@ void* malloc(size_t size)
|
||||||
continue;
|
continue;
|
||||||
if (!allocate_pool(i))
|
if (!allocate_pool(i))
|
||||||
break;
|
break;
|
||||||
|
// NOTE: always works since we just created the pool
|
||||||
return allocate_from_pool(i, size);
|
return allocate_from_pool(i, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue