diff --git a/tests/test/theap2.pp b/tests/test/theap2.pp
index f5153c06df..95baf5ddad 100644
--- a/tests/test/theap2.pp
+++ b/tests/test/theap2.pp
@@ -2,6 +2,7 @@ var
   a : array[0..3] of pointer;
   i,j : longint;
   HeapStatus : THeapStatus;
+  oldmemsize: ptruint;
 begin
   randomize;  
 {$if not(defined(CPU8)) and not(defined(CPU16))}
@@ -11,7 +12,16 @@ begin
       if not(assigned(a[j])) then
         getmem(a[j],1024*1024)
       else
-        reallocmem(a[j],MemSize(a[j])*11 div 10);
+        begin
+          oldmemsize:=MemSize(a[j]);
+          reallocmem(a[j],oldmemsize*11 div 10);
+          if pbyte(a[j])^<>123 then
+            halt(1);
+          if (pbyte(a[j])+oldmemsize-1)^<>231 then
+            halt(2);
+        end;
+      pbyte(a[j])^:=123;
+      pbyte(a[j]+memsize(a[j])-1)^:=231;
     end;
   for i:=0 to high(a) do
     freemem(a[i]);