Browse Source

Allow MemSize(nil) to match FreeMem(nil).

Rika Ichinose 9 months ago
parent
commit
ba7a76bf37
2 changed files with 4 additions and 0 deletions
  1. 2 0
      rtl/inc/heap.inc
  2. 2 0
      rtl/inc/heaptrc.pp

+ 2 - 0
rtl/inc/heap.inc

@@ -1303,6 +1303,8 @@ end;
 
 function SysMemSize(p: pointer): ptruint;
 begin
+  if not assigned(p) then
+    exit(0);
   result := pmemchunk_fixed(pointer(p)-sizeof(tmemchunk_fixed_hdr))^.size;
   if (result and fixedsizeflag) = 0 then
     result := result and sizemask-sizeof(tmemchunk_var_hdr)

+ 2 - 0
rtl/inc/heaptrc.pp

@@ -782,6 +782,8 @@ function TraceMemSize(p:pointer):ptruint;
 var
   pp : pheap_mem_info;
 begin
+  if not assigned(p) then
+    exit(0);
   pp:=pheap_mem_info(p-sizeof(theap_mem_info));
   TraceMemSize:=pp^.size;
 end;