diff --git a/src/system/kernel/heap.cpp b/src/system/kernel/heap.cpp index 45afcde207..59f3e257bd 100644 --- a/src/system/kernel/heap.cpp +++ b/src/system/kernel/heap.cpp @@ -1296,13 +1296,15 @@ heap_allocate_contiguous_pages(heap_allocator *heap, uint32 pageCount) continue; } - if (first > 0) { + if (first < 0) + first = i; + + if (first >= 0) { if ((i + 1 - first) == pageCount) { found = true; break; } - } else - first = i; + } } if (!found) { diff --git a/src/system/libroot/posix/malloc_debug/heap.cpp b/src/system/libroot/posix/malloc_debug/heap.cpp index c25a807156..1e3d0b9eb1 100644 --- a/src/system/libroot/posix/malloc_debug/heap.cpp +++ b/src/system/libroot/posix/malloc_debug/heap.cpp @@ -925,13 +925,15 @@ heap_allocate_contiguous_pages(heap_allocator *heap, uint32 pageCount) continue; } - if (first > 0) { + if (first < 0) + first = i; + + if (first >= 0) { if ((i + 1 - first) == pageCount) { found = true; break; } - } else - first = i; + } } if (!found) {