There is a memory leak on function GetSerialPortNames on unit LazSynaSer.
In that function local variable sr:TSearchRec is closed on the end of the function:
Line 2373
try
TmpPorts := '';
ScanForPorts( '/dev/rfcomm*',true);
// ScanForPorts( '/dev/pts/*');
ScanForPorts( '/dev/ttyUSB*',true);
ScanForPorts( '/dev/ttyS*',false);
ScanForPorts( '/dev/ttyAM*',true); // for ARM board
FindClose(sr); // <= WRONG PLACE, MOVE IT TO procedure ScanForPorts()
This causes a memory leak, after some research I found this link
https://www.freepascal.org/docs-html/rtl/sysutils/findfirst.html FindClose() should be called whenever FindFirst succeed. This means FindClose() should be placed inside the sub procedure ScanForPorts()
procedure ScanForPorts( const ThisRootStr : string; special : boolean); // added by PDF
var theDevice : String;
var FD : Cint;
var Ser : TSerialStruct;
begin
if FindFirst( ThisRootStr, $FFFFFFFF, sr) = 0 then
begin
repeat
......
until FindNext(sr) <> 0;
FindClose(sr); // <== FindClose() moved here
end;
end;
After this modification, my memory leak is gone. Attached are the patch to correct the problem.
I have also reported this problem to the github repository:
https://github.com/JurassicPork/TLazSerial/issues/3
Best regards,
Bambang