Wrong detected resource leak

delphi package - automated exception handling
Post Reply
MarcoNica
Posts: 2
Joined: Fri Feb 16, 2018 12:24 pm

Wrong detected resource leak

Post by MarcoNica »

I'm using madExcept 4.0.19 and get a wrong report for a resource leak in the code below.
MadExcept reports a leaked region that was created in CreateRectRgnIndirect.
But windows will manage the release of the region because GetDCEx with the flag DCX_INTERSECTRGN was called.

Here a little summary from the Microsoft documentation for the GetDcEx call:
hrgnClip [in]
A clipping region that may be combined with the visible region of the DC. If the value of flags is DCX_INTERSECTRGN or DCX_EXCLUDERGN, then the operating system assumes ownership of the region and will automatically delete it when it is no longer needed. In this case, the application should not use or delete the region after a successful call to GetDCEx.


Code: Select all

var
  rgn: HRGN;
  dc: HDC;
  nullRect: TRect;
begin
  nullRect := Rect(0,0,0,0);
  rgn := CreateRectRgnIndirect(nullRect);
  dc := GetDCEx(Handle, rgn, DCX_PARENTCLIP or DCX_CLIPSIBLINGS or DCX_INTERSECTRGN);
  ReleaseDC(Handle, dc);
end;
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Wrong detected resource leak

Post by madshi »

Good catch, thanks for letting me know! I'll fix this for the next build.
MarcoNica
Posts: 2
Joined: Fri Feb 16, 2018 12:24 pm

Re: Wrong detected resource leak

Post by MarcoNica »

Thank you for the fast replay.
anders_g
Posts: 3
Joined: Wed Dec 27, 2017 7:56 am

Re: Wrong detected resource leak

Post by anders_g »

Any timeframe for next build?
/Anders
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Wrong detected resource leak

Post by madshi »

I'm sorry for the delay in answering and fixing. I've now fixed this issue in my sources and the fix will be included in the next build, which I hope should be out later this week or early next week.
pp
Posts: 3
Joined: Fri Dec 19, 2008 8:26 am

Re: Wrong detected resource leak

Post by pp »

^ Friendly bump. Do you have a timeframe?

I have some codes from DevExpress that MadExcept / resources is flagging resource errors.
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Wrong detected resource leak

Post by madshi »

Sorry. You can use the latest beta build which (I think) has this fix included:

http://madshi.net/madCollectionBeta.exe

If not, let me know, then I'll recompile and upload a new build.
pp
Posts: 3
Joined: Fri Dec 19, 2008 8:26 am

Re: Wrong detected resource leak

Post by pp »

1. nope, it still doesn't fix the error.

2. This error is critical / show-stopping error.

Reason: Lot of vendors - TMS, LMD, DevExpress use the above routine in their code.

3. I ship my app with madExcept turned on.

I get random errors, not related to MadExcept triggering from inside TMS, LMD and DevEx. The vendors say MadExcept is faulty, I state it's the vendor's code that's shoddy.

Personally I think the code is faulty and the vendor is lying about it - as this is show-stopping. My app crashes and the code-break-point is inside DevEx's code; then TMS, then LMD.

Either way, it's not going nice nor well. So, can you provide a fix for this?
If you need to contact me privately please state so, so this bug can be quickly resolved.
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Wrong detected resource leak

Post by madshi »

Argh, I uploaded the last beta build one day before I made this fix in my sources. So here's a new beta build which should now really fix the problem:

http://madshi.net/madCollectionBeta.exe (installer 2.8.4.11)

I don't understand why it would be a critical / show stopper error, though. Leak reporting is not supposed to be turned on all the time, because it eats lots of RAM and slows everything down. It's intended to be turned on only on the development PC, or maybe sometimes for a very specific test on a customer PC. Of course madExcept itself should (usually) be always active. But leak reporting is a completely separate part.

Actually, unless you manually distribute madExcept32.dll with your EXE file, leak reporting will be automatically disabled on your users' PCs. Leak reporting requires madExcept32.dll to be present. On your development PC madExcept automatically finds madExcept32.dll if madCollection is properly installed. On your end users' PCs usually madExcept32.dll is not present. So by default leak reporting should be disabled on your end users' PCs, even if you have it enabled on your development PC.

If you get random errors, they are very VERY unlikely to be caused by this "wrong detected resource leak". All this little bug does is report a leak which isn't really a leak. But this should not result in any random errors. Furthermore, as described above, leak reporting shouldn't be active on your end users' PCs, anyway. So the reason for those random errors is probably something completely different.

If your app crashes and the code-break-point is inside DevEx/TMS/LMD code, then why do you think this has anything to do with leak reporting? Does this problem go away if you disable leak reporting? What is the exact madExcept crash report you get from this situation?
Post Reply