TortoiseSVN creates a new `HBITMAP` for each classic Explorer context-menu icon via `IconBitmapUtils::IconToBitmapPARGB32()`. The handles are assigned to `MENUITEMINFO::hbmpItem`, but they are not owned by the menu and are never released by either `IconBitmapUtils` or `CShellExt`.
The same context-menu code path in TortoiseGit was reproduced at runtime with ETW and Explorer crash dumps:
- Explorer terminated in `explorer!CTray::CheckGDIHandleLimit` with exception `0xc0000409`.
- The final dump contained 8,945 GDI handles, including 8,347 bitmap/SURFACE handles.
- Across 40 classic context-menu opens, the Explorer GDI count increased by 169.
- 160 of 177 outstanding type-5 bitmap creation stacks included `TortoiseGit.dll`.
- Disabling context-menu icons stopped the growth.
TortoiseGit tracking issue with the reproduction details:
https://gitlab.com/tortoisegit/tortoisegit/-/work_items/4278TortoiseSVN 1.14.9 and current trunk r29822 contain the equivalent allocation and ownership pattern. I have not installed TortoiseSVN on the affected machine, so the TortoiseSVN-specific runtime reproduction is not claimed here; the patch addresses the directly observable handle-lifetime defect in the source.
The attached patch:
- tracks successfully created menu-item `HBITMAP` handles on `CShellExt`;
- releases them with `DeleteObject()` when the shell-extension object is destroyed;
- avoids creating classic-menu bitmaps when no `HMENU` is supplied for the modern Explorer command path;
- avoids setting `MIIM_BITMAP` when no bitmap is used.
Verification performed:
- based on TortoiseSVN trunk r29822;
- changed lines formatted with the repository `.clang-format` using clang-format 15;
- unified diff checked by reversing and reapplying it against a clean sparse SVN working copy;
- full Windows/MSVC build not run because the available isolated Docker environment is Linux and cannot build the Windows ATL/MFC shell extension.
Microsoft's menu-item bitmap example explicitly frees application-created bitmap resources with `DeleteObject()`:
https://learn.microsoft.com/en-us/windows/win32/menurc/using-menusPlease review the ownership lifetime and, if possible, run the existing context-menu GDI-handle test against a TortoiseSVN build with this patch.