Fix heap delete to work with the moving of the HeapSegment header

This commit is contained in:
Gary Talent 2017-10-14 20:58:06 -05:00
parent fadfeea744
commit 6815402ba1

View File

@ -16,6 +16,10 @@ struct HeapSegment {
size_t size;
uint8_t inUse;
HeapSegment *next;
uint8_t *end() {
return ((uint8_t*) this) + this->size;
}
};
static HeapSegment *_heapIdx = nullptr;
@ -84,6 +88,12 @@ void operator delete(void *ptrIn) {
// ptr was found as a valid memory allocation, deallocate it
if (current) {
// move header back to end of segment
auto newCurrent = (HeapSegment*) current->end() - sizeof(HeapSegment);
*newCurrent = *current;
current = newCurrent;
prev->next = current;
// mark as not in use
current->inUse = false;