From f9efe01561663f3764be5ef5af6a9c4a13ea53b3 Mon Sep 17 00:00:00 2001 From: arunjose696 Date: Mon, 22 Sep 2025 09:14:36 +0200 Subject: [PATCH] Fix GDI handle leak when clearing MenuItem images When setting a null image on a MenuItem, the existing bitmap handle was overwritten with 0 without being released, causing a GDI handle leak if the MenuItem previously had an icon. This commit makes sure the handle is always deleted if it was set before. --- .../Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java index 95d99326705..40b07457046 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java @@ -807,6 +807,7 @@ private void updateImage () { info.hbmpItem = OS.HBMMENU_CALLBACK; } else { if (OS.IsAppThemed ()) { + if (hBitmap != 0) OS.DeleteObject (hBitmap); hBitmap = getMenuItemIconBitmapHandle(image); if ((style & (SWT.CHECK | SWT.RADIO)) != 0 && CUSTOM_SELECTION_IMAGE > 0) { info.fMask |= OS.MIIM_CHECKMARKS; @@ -895,7 +896,6 @@ private long getMenuItemIconBitmapHandle(Image image) { if (image == null) { return 0; } - if (hBitmap != 0) OS.DeleteObject (hBitmap); int zoom = adaptZoomForMenuItem(nativeZoom, image); return Display.create32bitDIB (image, zoom); }