From 5f0d1a006bf02e22893355f001641ac24046f9b0 Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Fri, 21 Apr 2017 09:49:26 +0100 Subject: [PATCH] shell32: Don't copy the imagelist in SHGetImageList(). Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- dlls/shell32/shellord.c | 12 ++-------- dlls/shell32/tests/shelllink.c | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/dlls/shell32/shellord.c b/dlls/shell32/shellord.c index 1a67a5298c4..96dd33aa304 100644 --- a/dlls/shell32/shellord.c +++ b/dlls/shell32/shellord.c @@ -2182,7 +2182,6 @@ HRESULT WINAPI SHGetImageList(int iImageList, REFIID riid, void **ppv) { HIMAGELIST hLarge, hSmall; HIMAGELIST hNew; - HRESULT ret = E_FAIL; /* Wine currently only maintains large and small image lists */ if ((iImageList != SHIL_LARGE) && (iImageList != SHIL_SMALL) && (iImageList != SHIL_SYSSMALL)) @@ -2192,16 +2191,9 @@ HRESULT WINAPI SHGetImageList(int iImageList, REFIID riid, void **ppv) } Shell_GetImageLists(&hLarge, &hSmall); - hNew = ImageList_Duplicate(iImageList == SHIL_LARGE ? hLarge : hSmall); + hNew = (iImageList == SHIL_LARGE) ? hLarge : hSmall; - /* Get the interface for the new image list */ - if (hNew) - { - ret = HIMAGELIST_QueryInterface(hNew, riid, ppv); - ImageList_Destroy(hNew); - } - - return ret; + return HIMAGELIST_QueryInterface(hNew, riid, ppv); } /************************************************************************* diff --git a/dlls/shell32/tests/shelllink.c b/dlls/shell32/tests/shelllink.c index c88e344b587..db15ccd7ed8 100644 --- a/dlls/shell32/tests/shelllink.c +++ b/dlls/shell32/tests/shelllink.c @@ -27,6 +27,7 @@ #include "shobjidl.h" #include "shlobj.h" #include "shellapi.h" +#include "commoncontrols.h" #include "wine/test.h" #include "shell32_test.h" @@ -1303,6 +1304,44 @@ todo_wine { DestroyIcon(hicon); } +static void test_SHGetImageList(void) +{ + HRESULT hr; + IImageList *list, *list2; + BOOL ret; + HIMAGELIST lg, sm; + ULONG start_refs, refs; + + hr = SHGetImageList( SHIL_LARGE, &IID_IImageList, (void **)&list ); + ok( hr == S_OK, "got %08x\n", hr ); + start_refs = IImageList_AddRef( list ); + IImageList_Release( list ); + + hr = SHGetImageList( SHIL_LARGE, &IID_IImageList, (void **)&list2 ); + ok( hr == S_OK, "got %08x\n", hr ); + ok( list == list2, "lists differ\n" ); + refs = IImageList_AddRef( list ); + IImageList_Release( list ); + ok( refs == start_refs + 1, "got %d, start_refs %d\n", refs, start_refs ); + IImageList_Release( list2 ); + + hr = SHGetImageList( SHIL_SMALL, &IID_IImageList, (void **)&list2 ); + ok( hr == S_OK, "got %08x\n", hr ); + + ret = Shell_GetImageLists( &lg, &sm ); + ok( ret, "got %d\n", ret ); + ok( lg == (HIMAGELIST)list, "mismatch\n" ); + ok( sm == (HIMAGELIST)list2, "mismatch\n" ); + + /* Shell_GetImageLists doesn't take a reference */ + refs = IImageList_AddRef( list ); + IImageList_Release( list ); + ok( refs == start_refs, "got %d, start_refs %d\n", refs, start_refs ); + + IImageList_Release( list2 ); + IImageList_Release( list ); +} + START_TEST(shelllink) { HRESULT r; @@ -1333,6 +1372,7 @@ START_TEST(shelllink) test_propertystore(); test_ExtractIcon(); test_ExtractAssociatedIcon(); + test_SHGetImageList(); CoUninitialize(); }