diff options
author | nickysn <nickysn@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2014-09-08 17:45:09 +0000 |
---|---|---|
committer | nickysn <nickysn@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2014-09-08 17:45:09 +0000 |
commit | 0e81f4ccaf23a74c4eaafa7ff3c6f6fc05c0cadb (patch) | |
tree | 4d95f6612c89cea63cc6b2ff9d6937a429884273 | |
parent | b234f6cc0ed96ee618d9c32d47e3cee5118de88b (diff) | |
download | fpc-0e81f4ccaf23a74c4eaafa7ff3c6f6fc05c0cadb.tar.gz |
* handle properly the case when RegisterTinyHeapBlock is called with a start
address equal or larger than HeapEnd
git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@28621 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r-- | rtl/inc/tinyheap.inc | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/rtl/inc/tinyheap.inc b/rtl/inc/tinyheap.inc index 925acdaf08..eccb82f1fd 100644 --- a/rtl/inc/tinyheap.inc +++ b/rtl/inc/tinyheap.inc @@ -294,6 +294,7 @@ procedure RegisterTinyHeapBlock(AAddress: pointer; ASize: ptruint); var alignment_inc: smallint; + p: PTinyHeapBlock; begin {$ifdef DEBUG_TINY_HEAP} Writeln('RegisterTinyHeapBlock(', ptruint(AAddress), ',', ASize, ')'); @@ -311,11 +312,34 @@ end else begin - if (HeapOrg=nil) or (TTinyHeapPointerArithmeticType(HeapOrg) > TTinyHeapPointerArithmeticType(AAddress)) then + if (TTinyHeapPointerArithmeticType(HeapOrg) > TTinyHeapPointerArithmeticType(AAddress)) then HeapOrg:=AAddress; - if (HeapEnd=nil) or (TTinyHeapPointerArithmeticType(HeapEnd) < (TTinyHeapPointerArithmeticType(AAddress)+ASize)) then - HeapEnd:=Pointer(TTinyHeapPointerArithmeticType(AAddress)+ASize); - InternalTinyFreeMem(AAddress, ASize); + if TTinyHeapPointerArithmeticType(AAddress) > TTinyHeapPointerArithmeticType(HeapEnd) then + begin + if TTinyHeapPointerArithmeticType(HeapPtr) = TTinyHeapPointerArithmeticType(HeapEnd) then + begin + if FreeList=HeapPtr then + FreeList:=AAddress + else + begin + p:=FreeList; + while p^.Next<>HeapPtr do + p:=p^.Next; + PTinyHeapBlock(HeapPtr)^.Next:=AAddress; + end; + end + else + begin + PTinyHeapBlock(HeapPtr)^.Size:=EncodeTinyHeapFreeBlockSize(TTinyHeapPointerArithmeticType(HeapEnd)-TTinyHeapPointerArithmeticType(HeapPtr)); + PTinyHeapBlock(HeapPtr)^.Next:=AAddress; + end; + HeapPtr:=AAddress; + HeapEnd:=Pointer(TTinyHeapPointerArithmeticType(AAddress)+ASize); + end + else if TTinyHeapPointerArithmeticType(AAddress) = TTinyHeapPointerArithmeticType(HeapEnd) then + HeapEnd:=Pointer(TTinyHeapPointerArithmeticType(AAddress)+ASize) + else + InternalTinyFreeMem(AAddress, ASize); end; end; |