Browse Source

* 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 -

nickysn 11 years ago
parent
commit
14057ef438
1 changed files with 4 additions and 4 deletions
  1. 4 4
      rtl/inc/tinyheap.inc

+ 4 - 4
rtl/inc/tinyheap.inc

@@ -41,7 +41,6 @@
       TTinyHeapBlock = record
       TTinyHeapBlock = record
         Next: PTinyHeapBlock;
         Next: PTinyHeapBlock;
         Size: TTinyHeapFreeBlockSize;
         Size: TTinyHeapFreeBlockSize;
-        EndAddr: pointer;
       end;
       end;
 
 
     const
     const
@@ -126,6 +125,7 @@
     procedure InternalTinyFreeMem(Addr: Pointer; Size: TTinyHeapFreeBlockSize);
     procedure InternalTinyFreeMem(Addr: Pointer; Size: TTinyHeapFreeBlockSize);
       var 
       var 
         b, p, prev: PTinyHeapBlock;
         b, p, prev: PTinyHeapBlock;
+        EndAddr: Pointer;
         concatenated: boolean;
         concatenated: boolean;
       begin
       begin
         repeat
         repeat
@@ -134,7 +134,7 @@
 
 
           b^.Next := TinyHeapBlocks;
           b^.Next := TinyHeapBlocks;
           b^.Size := Size;
           b^.Size := Size;
-          b^.EndAddr := pointer(TTinyHeapPointerArithmeticType(addr)+size);
+          EndAddr := pointer(TTinyHeapPointerArithmeticType(addr)+size);
 
 
           if TinyHeapBlocks = nil then
           if TinyHeapBlocks = nil then
             TinyHeapBlocks := b
             TinyHeapBlocks := b
@@ -145,7 +145,7 @@
 
 
               while assigned(p) do
               while assigned(p) do
                 begin
                 begin
-                  if p^.EndAddr = addr then
+                  if (TTinyHeapPointerArithmeticType(p)+p^.Size) = TTinyHeapPointerArithmeticType(Addr) then
                     begin
                     begin
                       addr:=p;
                       addr:=p;
                       size:=p^.size+size;
                       size:=p^.size+size;
@@ -156,7 +156,7 @@
                       concatenated:=true;
                       concatenated:=true;
                       break;
                       break;
                     end
                     end
-                  else if p = b^.EndAddr then
+                  else if p = EndAddr then
                     begin
                     begin
                       size:=p^.size+size;
                       size:=p^.size+size;
                       if prev = nil then
                       if prev = nil then