Downloads  |  Buy

Memory leak in Delphi unit v4.1.9.0

Memory leak in Delphi unit v4.1.9.0

Postby jonjon » October 18th, 2019, 8:52 am

Hi,
It looks like there are multiple memory leaks in TA's Delphi units in v4.1.9.0: memory is allocated using StrAlloc() before various method calls, but StrDispose() is only called afterwards if the method returned an error. It should be called no matter what happened, preferably in a try / finally block.
Thank you.
jonjon
 

Re: Memory leak in Delphi unit v4.1.9.0

Postby Wyatt » October 18th, 2019, 9:19 am

It returns the string to you. We don't dispose what you'll be using.
User avatar
Wyatt
Site Admin
 
Posts: 6083
Joined: July 11th, 2007, 10:30 pm
Location: New Hampshire

Re: Memory leak in Delphi unit v4.1.9.0

Postby jonjon » October 18th, 2019, 9:29 am

Well, I believe that you are wrong because you are assigning the newly allocated string to the result so it needs to be freed first. Delphi compiler magic already handles the "Result" variable string so you'll need to take care of the extraData that you manually allocated first.
See the following methods for example, your code is basically ReturnString_WITH_LEAK when it should be ReturnString_OK:

function ReturnString_OK: string;
var
extraData : PWideChar;
begin
extraData := StrAlloc(10);
try
Result := extraData;
finally
StrDispose(extraData);
end;
end;

function ReturnString_WITH_LEAK: string;
var
extraData : PWideChar;
begin
extraData := StrAlloc(10);
Result := extraData;
if (False) then StrDispose(extraData);
end;
jonjon
 

Re: Memory leak in Delphi unit v4.1.9.0

Postby jonjon » October 25th, 2019, 3:15 am

Could you please confirm this ?
Thank you.
jonjon
 

Re: Memory leak in Delphi unit v4.1.9.0

Postby Wyatt » October 25th, 2019, 5:11 am

We’re looking into it
User avatar
Wyatt
Site Admin
 
Posts: 6083
Joined: July 11th, 2007, 10:30 pm
Location: New Hampshire


Return to LimeLM, TurboActivate, & TurboFloat Support