diff --git a/src/system/kernel/heap.cpp b/src/system/kernel/heap.cpp index ddd0a5c807..47356b9de8 100644 --- a/src/system/kernel/heap.cpp +++ b/src/system/kernel/heap.cpp @@ -1808,7 +1808,7 @@ heap_index_for(size_t size, int32 cpu) break; } - return index + cpu * HEAP_CLASS_COUNT; + return (index + cpu * HEAP_CLASS_COUNT) % sHeapCount; } @@ -2110,6 +2110,10 @@ memalign(size_t alignment, size_t size) shouldGrow = heap_should_grow(heap); break; } + +#if PARANOID_HEAP_VALIDATION + heap_validate_heap(heap); +#endif } if (result == NULL) { @@ -2128,10 +2132,6 @@ memalign(size_t alignment, size_t size) release_sem_etc(sHeapGrowSem, 1, B_DO_NOT_RESCHEDULE); } -#if PARANOID_HEAP_VALIDATION - heap_validate_heap(heap); -#endif - if (result == NULL) panic("heap: kernel heap has run out of memory\n"); return result;