Recent

Author Topic: [SOLVED] FPC 3.2.2/4 problem with the old memory manager (or my code 💁‍♂️)  (Read 229 times)

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 305
  • I use FPC [main] 💪🐯💪
FPC 3.2.2 & 3.2.4 x64 Windows

Code: Pascal  [Select][+][-]
  1. program app;
  2. begin
  3.   for argc:=9 to 9 do
  4.     GetMem(1);
  5. end.

Code: Pascal  [Select][+][-]
  1. Access violation reading from address $FFFFFFFFFFFFFFFF
« Last Edit: November 27, 2025, 07:39:05 am by ALLIGATOR »
I may seem rude - please don't take it personally

Khrys

  • Sr. Member
  • ****
  • Posts: 366
Re: FPC 3.2.2/4 problem with the old memory manager (or my code 💁‍♂️)
« Reply #1 on: November 27, 2025, 06:58:24 am »
I don't know what else you'd expect to happen when carelessly manipulating the argument count like that  :P

Take a look at  InternalExit  in  system.inc,  called on program shutdown:

Code: Pascal  [Select][+][-]
  1. {$if (defined(MSWINDOWS) and not defined(win16)) or defined(OS2)}
  2.   { finally release the heap if possible, especially
  3.     important for DLLs.
  4.     Reset the array to nil, and finally also argv itself to
  5.     avoid double freeing problem in case this function gets called twice. }
  6.   if assigned(argv) then
  7.     begin
  8.       for i:=0 to argc-1 do
  9.         if assigned(argv[i]) then
  10.           begin
  11.             sysfreemem(argv[i]);
  12.             argv[i]:=nil;
  13.           end;
  14.       sysfreemem(argv);
  15.       argv:=nil;
  16.     end;
  17. {$endif}

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 305
  • I use FPC [main] 💪🐯💪
Well, well!

In my defense, I will say that I don't have debug symbols for version 3.2.2/3.2.4, so I couldn't diagnose it properly. And on FPC [main], the behavior did not repeat itself.

Thank you)
I may seem rude - please don't take it personally

 

TinyPortal © 2005-2018