Memory allocation for cmdline in the rtl on macOS
Summary
Memory allocation for cmdline in the rtl on MacOS is inconsistent and can lead to crashes
System Information
MacOS 14.7
Problem description
rtl/inc/systemh.inc initialises cmdline to nil with var CmdLine:Pchar=nil; rtl/bsd/system.pp calls reallocmem(cmdline, ...) rtl/inc/system.inc calls sysfreemem(cmdline)
The calls to reallocmem and sysfreemem are inconsistent and this will lead to a crash (in sysfreemem) at program exit, if e.g. the memory manager at the time of realloc is the C memory manager.
Possible fixes
- call sysreallocmem(cmdline, ...) in rtl/bsd/system.pp rather than reallocmem(cmdline, ...)
- check to see if sysmem calls are used on other platforms for the (global) cmdline variable
Edited by Adriaan Van Os