Skip to content

Commit 0f59d69

Browse files
author
devsh
committed
fix a nasty bug in GeneralpurposeAddressAllocator
1 parent a5a05e7 commit 0f59d69

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

examples_tests

include/nbl/core/alloc/GeneralpurposeAddressAllocator.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,9 @@ class GeneralpurposeAddressAllocatorStrategy<_size_type,false> : protected Gener
393393
if (!Base::freeListStackCtr[level])
394394
continue;
395395

396-
// pop off the top
397-
const Block& popped = Base::freeListStack[level][--Base::freeListStackCtr[level]];
396+
const auto newStackSize = Base::freeListStackCtr[level]-1;
397+
// try pop off the top
398+
const Block& popped = Base::freeListStack[level][newStackSize];
398399
Block allocatedBlock;
399400
size_type wastedSpace = Base::calcSubAllocation(allocatedBlock,&popped,bytes,alignment);
400401
// the minimum size of the free blocks that would have been created before and after the allocation would not satisfy the minimum
@@ -407,6 +408,7 @@ class GeneralpurposeAddressAllocatorStrategy<_size_type,false> : protected Gener
407408
#endif // _NBL_DEBUG
408409
return {{invalid_address,invalid_address},{invalid_address,invalid_address}};
409410
}
411+
Base::freeListStackCtr[level] = newStackSize;
410412
Base::freeSize -= popped.getLength();
411413
return {allocatedBlock,popped};
412414
}

0 commit comments

Comments
 (0)