Memory leak in RB 14.02 ppXHTMLRendererGeneric
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;
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;
This discussion has been closed.
Comments
Thanks for pointing this out. There is now a patch for RB 14.02 that
makes your proposed changes.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com