Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Memory leak in RB 14.02 ppXHTMLRendererGeneric

edited December 2011 in General
Hello,
There is a memory leak in
TppXHTMLRendererGeneric.CreateImageForDrawCommand. lMetaFile is created
but now freed.

Code before :

function
TppXHTMLRendererGeneric.CreateImageForDrawCommand(aDrawCommand:
TppDrawCommand; aRect: TRect): String;
var
lBitmap: TBitmap;
lMetaFile: TMetaFile;
begin
lMetaFile := aDrawCommand.AsMetaFile; <<<---Leak

if (lMetaFile <> nil) then
begin
lBitmap := TBitmap.Create;
lBitmap.Width := aRect.Right - aRect.Left;
lBitmap.Height := aRect.Bottom - aRect.Top;
lBitmap.Canvas.StretchDraw(Rect(0, 0, lBitmap.Width,
lBitmap.Height), lMetaFile);
end
else
lBitmap := TppFileDeviceUtils.DrawCommandToBitmap(aDrawCommand,
ScalePercentage, TransparencyColor);

try
lBitmap.Transparent := True;
lBitmap.TransparentColor := TransparencyColor;
Result := SaveBitmapToGIF(lBitmap);
finally
lBitmap.Free;
end;
end;



Fixed Code :

function
TppXHTMLRendererGeneric.CreateImageForDrawCommand(aDrawCommand:
TppDrawCommand; aRect: TRect): String;
var
lBitmap: TBitmap;
lMetaFile: TMetaFile;
begin

lMetaFile := aDrawCommand.AsMetaFile;
try
if (lMetaFile <> nil) then
begin
lBitmap := TBitmap.Create;
lBitmap.Width := aRect.Right - aRect.Left;
lBitmap.Height := aRect.Bottom - aRect.Top;
lBitmap.Canvas.StretchDraw(Rect(0, 0, lBitmap.Width,
lBitmap.Height), lMetaFile);
end
else
lBitmap := TppFileDeviceUtils.DrawCommandToBitmap(aDrawCommand,
ScalePercentage, TransparencyColor);

try

lBitmap.Transparent := True;
lBitmap.TransparentColor := TransparencyColor;

Result := SaveBitmapToGIF(lBitmap);

finally
lBitmap.Free;
end;
finally
if assigned(lMetaFile) then lMetaFile.free ;
end;

end;

Comments

This discussion has been closed.