Menu ▾ ▴

#158 Catalogue loaded from resources leaks while UseMemoryMappedFiles = True (dx_SupportsResources)

v1.0 (example)
open
nobody
None
5
2 days ago
2 days ago
No

With dx_SupportsResources defined, TMoFile.Create reads a catalogue from an RCDATA resource with GetMem but keeps FUseMemoryMappedFiles as passed in (True by default on Windows). TMoFile.Destroy then takes the memory-mapped branch: UnMapViewOfFile on a GetMem block and CloseHandle(0) twice; the block itself is never freed. Every catalogue that is released (on UseLanguage and at shutdown) leaks its full size; ReportMemoryLeaksOnShutdown shows it.

Code unchanged in trunk r212; seen with Delphi 13, Win64.

Repro: define dx_SupportsResources, embed a default.mo as RCDATA (LOCALE_DE_DEFAULT), call UseLanguage('de'), then UseLanguage('en'), exit with ReportMemoryLeaksOnShutdown := True.

Fix: in the resource branch of TMoFile.Create, after mofile.ReadBuffer(momemory^, size); add:

FUseMemoryMappedFiles := False;

Workaround: DefaultInstance.UseMemoryMappedFiles := False before the first catalogue is opened.

Discussion


Log in to post a comment.