weird issue with "report resource leaks" and Allocmem + SSE2

delphi package - automated exception handling
Post Reply
brian
Posts: 45
Joined: Fri Feb 29, 2008 11:12 am

weird issue with "report resource leaks" and Allocmem + SSE2

Post by brian »

Hi,

I encountered an odd issue: when I have the memory leak report option enabled, the following code triggers an exception with "Invalid floating point operation", but only the 1st time it is used. If I call it again there is no exception and the call succeeds. When closing the app there is this report about a leak:

Image

the test code:

Code: Select all

function FastJpegFileToBitmap(fle: string): Graphics.TBitmap;
Var PJ: PJpegDecode;
     j: TJpegImage;
     m: TMemoryStream;
     err: TJpegDecodeError;
begin
  Result := nil;

  m := TMemoryStream.Create;
  With m do begin
    Try
      LoadFromFile(fle);
    Except
      m.Free;
      Exit;
    End;
    try
      Err := jpegdec.JpegDecode(Memory,Size,PJ);
    except
      On E:Exception
       do ShowMessage(e.Message);
    end;
    if Err <> JPEG_SUCCESS then begin
      ShowMessage('pic error');
      showmessage(jpegdec.JpegErrorToStream(Err));
      //
      m.Free;
      PJ^.Free;
      // use default
      j := TJPEGImage.Create;
      j.Performance := jpBestSpeed;
      try
        Result := Graphics.TBitmap.Create;
        j.LoadFromFile(fle);
        With Result do begin
          Height := j.Height;
          Width  := j.Width;
          Assign(j);
        end;
      except
        FreeAndNil(Result);
        FreeAndNil(j);
        Exit;
      end;
      FreeAndNil(j);
      Exit;
    end;
    showmessage('success');
    // SSE Jpeg success
    Result := PJ^.ToBitmap;
    PJ^.Free;
  end;
  m.Free;
end;
the jpegdec unit: http://pastebin.com/AY4rLvdi (developed by http://synopse.info)

Is this an issue with madExcept or something related to the jpegdec unit?
I tested without madExcept, using only ReportMemoryLeaksOn.. and also with FastMM4 fulldebug mode, it worked fine in those cases, no exception and no memory leak reported.
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Re: weird issue with "report resource leaks" and Allocmem +

Post by madshi »

The exception should be fixed in the following build (I hope). Could you please check and confirm?

http://madshi.net/madCollectionBeta.exe

The leak looks like a real leak, from what I can see right now. "ReportMemoryLeaksOn" and FastMM4 can't find this leak because they do not check VirtualAlloc allocations for leaks. madExcept hooks about 400 APIs to report all kinds of leaks to you (memory allocations, handles, GDI objects, user objects, etc etc). "ReportMemoryLeaksOn" and FastMM4 are very very limited in their leak reporting capability in comparison.
brian
Posts: 45
Joined: Fri Feb 29, 2008 11:12 am

Re: weird issue with "report resource leaks" and Allocmem +

Post by brian »

Nice! I confirm the beta fixed this issue. There is no exception now, the code executes successively the first time, and no leak is reported at the end, I got a small window in the tray with "Well done! - no leaks found".

Nice to see these libraries still supported :) I've been using it for many years now for mostly hobby applications, and it has been tremendously helpful. Think I first came across it from back in the days when E-E (experts-exchange) was popular and free and there was a big Delphi community, like 10-12 years back.
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Re: weird issue with "report resource leaks" and Allocmem +

Post by madshi »

I'm a bit surprised the leak is gone, too. Maybe it was a result of the exception. Anyway, all is good, I guess...
Post Reply