From 14057ef438684fcc821dfd8d4287818f7e5a9777 Mon Sep 17 00:00:00 2001 From: nickysn Date: Fri, 15 Aug 2014 00:33:33 +0000 Subject: [PATCH] * rm EndAddr from the TTinyHeapBlock structure. This: 1) fixes a bug, which causes the next TTinyHeapBlock to be overwritten after freeing a memory block, allocated by GetMem(sizeof(pointer)). This bug was exposed after r28391, but was present before that; this commit only made the damage worse and, therefore, more visible. 2) brings the internal heap structure closer to the TP7 heap. git-svn-id: trunk@28416 - --- rtl/inc/tinyheap.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rtl/inc/tinyheap.inc b/rtl/inc/tinyheap.inc index b2ae6dc450..f95c0ab26b 100644 --- a/rtl/inc/tinyheap.inc +++ b/rtl/inc/tinyheap.inc @@ -41,7 +41,6 @@ TTinyHeapBlock = record Next: PTinyHeapBlock; Size: TTinyHeapFreeBlockSize; - EndAddr: pointer; end; const @@ -126,6 +125,7 @@ procedure InternalTinyFreeMem(Addr: Pointer; Size: TTinyHeapFreeBlockSize); var b, p, prev: PTinyHeapBlock; + EndAddr: Pointer; concatenated: boolean; begin repeat @@ -134,7 +134,7 @@ b^.Next := TinyHeapBlocks; b^.Size := Size; - b^.EndAddr := pointer(TTinyHeapPointerArithmeticType(addr)+size); + EndAddr := pointer(TTinyHeapPointerArithmeticType(addr)+size); if TinyHeapBlocks = nil then TinyHeapBlocks := b @@ -145,7 +145,7 @@ while assigned(p) do begin - if p^.EndAddr = addr then + if (TTinyHeapPointerArithmeticType(p)+p^.Size) = TTinyHeapPointerArithmeticType(Addr) then begin addr:=p; size:=p^.size+size; @@ -156,7 +156,7 @@ concatenated:=true; break; end - else if p = b^.EndAddr then + else if p = EndAddr then begin size:=p^.size+size; if prev = nil then