Hallo,
ich ermittele die "Language ID" (Sprache von Windows) mit diesem Code:
Delphi-Quellcode:
function GetWindowsLanguage(LCTYPE: LCTYPE {type of information}): string;
var
Buffer : PChar;
Size : integer;
begin
Size := GetLocaleInfo (LOCALE_USER_DEFAULT, LCType, nil, 0);
GetMem(Buffer, Size);
try
GetLocaleInfo (LOCALE_USER_DEFAULT, LCTYPE, Buffer, Size);
Result := string(Buffer);
finally
FreeMem(Buffer); <-- Speicherleck hier
end;
end;
Aufruf mit:
GetWindowsLanguage(LOCALE_ILANGUAGE);
gefunden unter
https://www.swissdelphicenter.ch/de/showcode.php?id=320
Nun habe ich FastMM5 eingebunden und der zeigt an, dass es ein Speicherleck gibt:
Code:
---------------------------
Memory Corruption Detected
---------------------------
A memory block footer has been corrupted.
The block size is 5.
The block was allocated by thread 0x1C3C, and the stack trace (return addresses) at the time was:
00425680 [FastMM5.pas][FastMM5][FastMM_DebugGetMem_GetDebugBlock][7292]
004256FB [FastMM5.pas][FastMM5][FastMM_DebugGetMem][7315]
0040755E [System][System][@GetMem]
00BF9A33 [test.pas][test][GetWindowsLanguage][20235]
....
The allocation number is: 51923
Current memory dump of 13 bytes starting at pointer address 8333020:
30 00 34 00 30 00 37 00 00 00 80 80 80
0 . 4 . 0 . 7 . . . . . .
Wie kann ich das beheben?