You are not logged in.
Pages: 1
Delphi 11.1, mORMot 3547
I have a method based services with several functions. They all work fine, only this function creates a memory leak.
if (pmCtxt.Method = mGET)
and GetSessionUserDirName(pmCtxt, dirName)
and UrlDecodeNeedParameters(pmCtxt.Parameters, TFileServiceFunction.Param.LoadFile_ImageName) then
begin
Utf8ToFileName(pmCtxt.InputUtf8[TFileServiceFunction.Param.LoadFile_ImageName], imageName);
if ExtractFileExt(imageName) = '' then
imageName := ChangeFileExt(imageName, DEFAULT_FILE_EXT);
fileName := MakePath([DataFolder, dirName, imageName]);
if FileExists(fileName) then
begin
pmCtxt.ReturnFile(fileName);
Exit; //=>
end;
end;
When I run this function once, I get this message when closing the server:
Press [Enter] to quit server...
Unexpected Memory Leak
An unexpected memory leak has occurred. The unexpected small block leaks are:
13 - 20 bytes: TFileStream x 1
125 - 132 bytes: UnicodeString x 1
When I run this function three times, I get this message:
Press [Enter] to quit server...
Unexpected Memory Leak
An unexpected memory leak has occurred. The unexpected small block leaks are:
13 - 20 bytes: TFileStream x 3
141 - 148 bytes: UnicodeString x 3
The function ReturnFile() is called only here, other functions also elsewhere.
What could be the reason?
With best regards
Thomas
Offline
I use the Http server (useHttpSocket). In the function THttpRequestContext.ContentFromFile() the FileStream is created but not released. Also the function THttpRequestContext.ProcessDone is not called. Thus, there is no point at which the FileStream is released again. I think this change came with the Async server.
So, a FileStream is created which is not destroyed anymore. This creates the memory leak.
With best regards
Thomas
Last edited by tbo (2022-07-05 11:12:29)
Offline
You are right.
Please try https://github.com/synopse/mORMot2/commit/a5842119
Offline
Pages: 1