[PATCH 2/2] user32: Free the created icon handle when using LR_COPYFROMRESOURCE.

Zebediah Figura zfigura at codeweavers.com
Thu Dec 16 11:58:38 CST 2021


Spotted by John Sullivan.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52207
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
 dlls/user32/cursoricon.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/dlls/user32/cursoricon.c b/dlls/user32/cursoricon.c
index 35f13a1a91b..76f13a775e3 100644
--- a/dlls/user32/cursoricon.c
+++ b/dlls/user32/cursoricon.c
@@ -3100,6 +3100,7 @@ HANDLE WINAPI CopyImage( HANDLE hnd, UINT type, INT desiredx,
             struct cursoricon_frame *frame;
             struct cursoricon_object *icon;
             int depth = (flags & LR_MONOCHROME) ? 1 : get_display_bpp();
+            HICON resource_icon = NULL;
             ICONINFO info;
             HICON res;
 
@@ -3107,10 +3108,14 @@ HANDLE WINAPI CopyImage( HANDLE hnd, UINT type, INT desiredx,
 
             if (icon->rsrc && (flags & LR_COPYFROMRESOURCE))
             {
-                hnd = CURSORICON_Load( icon->module, icon->resname, desiredx, desiredy, depth,
-                                       !icon->is_icon, flags );
+                resource_icon = CURSORICON_Load( icon->module, icon->resname, desiredx,
+                                                 desiredy, depth, !icon->is_icon, flags );
                 release_user_handle_ptr( icon );
-                if (!(icon = get_icon_ptr( hnd ))) return 0;
+                if (!(icon = get_icon_ptr( resource_icon )))
+                {
+                    if (resource_icon) DestroyIcon( resource_icon );
+                    return 0;
+                }
             }
             frame = get_icon_frame( icon, 0 );
 
@@ -3143,6 +3148,7 @@ HANDLE WINAPI CopyImage( HANDLE hnd, UINT type, INT desiredx,
                     {
                         release_icon_frame( icon, frame );
                         release_user_handle_ptr( icon );
+                        if (resource_icon) DestroyIcon( resource_icon );
                         return 0;
                     }
                     stretch_bitmap( info.hbmColor, frame->color, desiredx, desiredy,
@@ -3153,6 +3159,7 @@ HANDLE WINAPI CopyImage( HANDLE hnd, UINT type, INT desiredx,
                         DeleteObject( info.hbmColor );
                         release_icon_frame( icon, frame );
                         release_user_handle_ptr( icon );
+                        if (resource_icon) DestroyIcon( resource_icon );
                         return 0;
                     }
                     stretch_bitmap( info.hbmMask, frame->mask, desiredx, desiredy,
@@ -3165,6 +3172,7 @@ HANDLE WINAPI CopyImage( HANDLE hnd, UINT type, INT desiredx,
                     if (!(info.hbmMask = CreateBitmap( desiredx, desiredy * 2, 1, 1, NULL )))
                     {
                         release_user_handle_ptr( icon );
+                        if (resource_icon) DestroyIcon( resource_icon );
                         return 0;
                     }
                     stretch_bitmap( info.hbmMask, frame->mask, desiredx, desiredy * 2,
@@ -3181,6 +3189,7 @@ HANDLE WINAPI CopyImage( HANDLE hnd, UINT type, INT desiredx,
             release_user_handle_ptr( icon );
 
             if (res && (flags & LR_COPYDELETEORG)) DestroyIcon( hnd );
+            if (resource_icon) DestroyIcon( resource_icon );
             return res;
         }
     }
-- 
2.34.1




More information about the wine-devel mailing list