• Welcome to Vampyre Imaging Library Forum. Please login or sign up.
 

Memory leak after attempting to load a corrupt JPG

Started by cabbott, 15 October 2009, 11:49:05

Previous topic - Next topic

cabbott

I have a fix, but you will probably want to track down the actual cause in the JPEG code and fix it properly.

LoadImageFromStream in Imaging.pas terminates prematurely if an exception occurs in Format.LoadFromStream(). It then leaves an entry in IArray with memory allocated that is never freed or allocated back to the callers Image property so the caller or FreeImage() can clear it.

Code snippet with amendments in bold:
try
    Result := Format.LoadFromStream(Stream, IArray, True);
    if Result and (Length(IArray) > 0) then
    begin
      Image := IArray[0];
      for I := 1 to Length(IArray) - 1 do
        FreeImage(IArray);
    end
    else begin
      Result := False;
    end;
except
      Result:=False;
      for I := 0 to Length(IArray) - 1 do
        FreeImage(IArray);
end;

Galfar

Thanks for the fix.

Could you please upload this corrupt JPEG here so I could test if the exception is raised by Imaging or JpegLib?

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Name:
Email:

Shortcuts: ALT+S save/post or ALT+P preview

SMF spam blocked by CleanTalk