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 năm trước cách đây
mục cha
commit
14057ef438
1 tập tin đã thay đổi với 4 bổ sung4 xóa
  1. 4 4
      rtl/inc/tinyheap.inc

+ 4 - 4
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