d2lmirrors / anolis

Anolis is the underlying project for the XPize and Vize resource switchers for Windows XP and Vista respectivly. The codebase allows for the easy swapping around of resources within Win32 executables and other files. (just adding some missing data)
GNU General Public License v2.0
1 stars 0 forks source link

Serious GDI+ Handle Leakage #29

Closed Dobby233Liu closed 1 year ago

Dobby233Liu commented 1 year ago

creation date = 2009-03-13T18:10:01.033-07:00

GDI+ handles, when created in the ImageResourceData subclasses, are not being disposed of properly.   You can mask the problem by making all ImageResourceData subclasses lazy-load GDI+ objects (as they do in the 32209 changeset) but that doesn't mean the capability for it to leak 9997 GDI+ handles before crashing won't happen again.   Whilst I've properly implemented IDisposable where it counts, I'm not properly disposing objects. This will require a fairly extensive code review.

Dobby233Liu commented 1 year ago

closed date: 2009-03-14T17:41:51.417-07:00

The problem was threefold:

a) Things weren't getting disposed properly. This has been solved by a minor code review. b) There were preemptive calls to CreateIconFromResourceEx whenever an IconCursorImageResourceData was created. I've corrected this by postponing the call until the .Icon (and consequently, the .Bitmap) property accessor is called. The downside is that you won't get errors about malformed IconCursor images until later, but that's a rarity. c) There were also preemptive calls to icon.ToBitmap() and other cases where Bitmaps were created and never used. This was fixed by delegating the creation to the .Image property accessor, which is now an abstract property (rather than a concrete auto-implemented property) of ImageResourceData

Thanks to Brendan Grant for the confirmation and resolution tips.