diff --git a/rtl/inc/heap.inc b/rtl/inc/heap.inc index 3a82b7b08d..3c9a99d17c 100644 --- a/rtl/inc/heap.inc +++ b/rtl/inc/heap.inc @@ -1571,6 +1571,9 @@ var i : longint; {$endif} begin + { Do not try to do anything if the heap manager already reported an error } + if (errorcode=203) or (errorcode=204) then + exit; loc_freelists := @freelists; {$ifdef FPC_HAS_FEATURE_THREADING} if heap_lock_use > 0 then diff --git a/rtl/inc/system.inc b/rtl/inc/system.inc index 4f565b51e7..d6dae6a246 100644 --- a/rtl/inc/system.inc +++ b/rtl/inc/system.inc @@ -989,10 +989,14 @@ Begin {$endif} {$ifdef LINUX} {sysfreemem already checks for nil} - sysfreemem(calculated_cmdline); + { Do not try to do anything if the heap manager already reported an error } + if (errorcode<>203) and (errorcode<>204) then + sysfreemem(calculated_cmdline); {$endif} {$ifdef BSD} - sysfreemem(cmdline); + { Do not try to do anything if the heap manager already reported an error } + if (errorcode<>203) and (errorcode<>204) then + sysfreemem(cmdline); {$endif} {$ifdef FPC_HAS_FEATURE_HEAP}