Setlength generates memory leak.
Hi, This function generates a memory leak: ` function AsString(const DataPtr:Pointer;const DataLen:Integer):string; var Offset : NativeInt; i : Integer; begin if DataPtr=nil then Result := '' else begin Offset := NativeInt(DataPtr)-1; SetLength(Result,DataLen); for i:=1 to Length(Result) do Result[i] := Chr(PByte(Offset+i)^); end; end;
And this is the report:
A memory block has been leaked. The size is: 36
This block was allocated by thread 0x22DC, and the stack trace (return addresses) at the time was: 4077A6 [System][System.@GetMem] 40B137 [System][System.@NewUnicodeString] 40C38F [System][System.@UStrSetLength] 92B012 [uCore.pas][uCore][uCore.AsString][2405] 8E32FF [uCrypt.pas][uCrypt][uCrypt.GetNameEntryByNID][544] 8E4DB0 [uCrypt.pas][uCrypt][uCrypt.X509Parse][1174] 8E7E88 [uCrypt.pas][uCrypt][uCrypt.CertToPKI][3187] 8E8031 [uCrypt.pas][uCrypt][uCrypt.PKIFromCert][3217] C0621B [uSocket.pas][uSocket][uSocket.TExTCPClient.DoOnConnected][2681] C037AC [uSocket.pas][uSocket][uSocket.TTCPClientThread.InternalConnect][779] C0390F [uSocket.pas][uSocket][uSocket.TTCPClientThread.Execute][817]
The block is currently used for an object of class: UnicodeString
The allocation number is: 527357 `
http://fgaillard.com/2011/02/when-the-debugger-leaks/