|
@@ -86,7 +86,16 @@ void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
|
|
|
|
|
|
|
|
|
#if defined (SPLITTING_FIXED) || defined (SPLITTING_VARIABLE)
|
|
|
- new_size = get_size(ptr) - size - HEADER_SIZE;
|
|
|
+
|
|
|
+ * one.
|
|
|
+ * Note: new_size is a size_t, so compare first in order to prevent an
|
|
|
+ * underflow.
|
|
|
+ */
|
|
|
+ if(get_size(ptr) > size + HEADER_SIZE) {
|
|
|
+ new_size = get_size(ptr) - size - HEADER_SIZE;
|
|
|
+ } else {
|
|
|
+ new_size = 0;
|
|
|
+ }
|
|
|
|
|
|
#ifdef SPLITTING_FIXED
|
|
|
min_split_size = MIN_SPLITTING_SIZE;
|
|
@@ -95,13 +104,13 @@ void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
|
|
|
min_split_size = heap->dmm_knobs.min_split_size;
|
|
|
#endif
|
|
|
|
|
|
- if(new_size > min_split_size) {
|
|
|
+ if(new_size >= min_split_size) {
|
|
|
split(allocator, heap, ptr, size);
|
|
|
}
|
|
|
-#else
|
|
|
- mark_used(ptr);
|
|
|
#endif
|
|
|
|
|
|
+ mark_used(ptr);
|
|
|
+
|
|
|
#ifdef FUTURE_FEATURES
|
|
|
|
|
|
push_block(&ptr, &heap->used_blocks_head);
|