diff --git a/dlls/comctl32/imagelist.c b/dlls/comctl32/imagelist.c index a49622cdde8..cc9248671d4 100644 --- a/dlls/comctl32/imagelist.c +++ b/dlls/comctl32/imagelist.c @@ -692,25 +692,6 @@ ImageList_Destroy (HIMAGELIST himl) if (!is_valid(himl)) return FALSE; - /* delete image bitmaps */ - if (himl->hbmImage) - DeleteObject (himl->hbmImage); - if (himl->hbmMask) - DeleteObject (himl->hbmMask); - - /* delete image & mask DCs */ - if (himl->hdcImage) - DeleteDC(himl->hdcImage); - if (himl->hdcMask) - DeleteDC(himl->hdcMask); - - /* delete blending brushes */ - if (himl->hbrBlend25) - DeleteObject (himl->hbrBlend25); - if (himl->hbrBlend50) - DeleteObject (himl->hbrBlend50); - - /* Free the IImageList instance */ IImageList_Release((IImageList *) himl); return TRUE; } @@ -2972,7 +2953,22 @@ static ULONG WINAPI ImageListImpl_Release(IImageList *iface) TRACE("(%p) refcount=%u\n", iface, ref); if (ref == 0) + { + /* delete image bitmaps */ + if (This->hbmImage) DeleteObject (This->hbmImage); + if (This->hbmMask) DeleteObject (This->hbmMask); + + /* delete image & mask DCs */ + if (This->hdcImage) DeleteDC (This->hdcImage); + if (This->hdcMask) DeleteDC (This->hdcMask); + + /* delete blending brushes */ + if (This->hbrBlend25) DeleteObject (This->hbrBlend25); + if (This->hbrBlend50) DeleteObject (This->hbrBlend50); + + This->lpVtbl = NULL; HeapFree(GetProcessHeap(), 0, This); + } return ref; } diff --git a/dlls/comctl32/tests/imagelist.c b/dlls/comctl32/tests/imagelist.c index a931e9cf43c..b97ca9a5889 100644 --- a/dlls/comctl32/tests/imagelist.c +++ b/dlls/comctl32/tests/imagelist.c @@ -1251,8 +1251,36 @@ static void test_iimagelist(void) IImageList *imgl; HIMAGELIST himl; HRESULT hr; + ULONG ret; - if (!pImageList_CoCreateInstance || !pHIMAGELIST_QueryInterface) + if (!pHIMAGELIST_QueryInterface) + { + win_skip("XP imagelist functions not available\n"); + return; + } + + /* test reference counting on destruction */ + imgl = (IImageList*)createImageList(32, 32); + ret = IUnknown_AddRef(imgl); + ok(ret == 2, "Expected 2, got %d\n", ret); + ret = ImageList_Destroy((HIMAGELIST)imgl); + ok(ret == TRUE, "Expected TRUE, got %d\n", ret); + ret = ImageList_Destroy((HIMAGELIST)imgl); + ok(ret == TRUE, "Expected TRUE, got %d\n", ret); + ret = ImageList_Destroy((HIMAGELIST)imgl); + ok(ret == FALSE, "Expected FALSE, got %d\n", ret); + + imgl = (IImageList*)createImageList(32, 32); + ret = IUnknown_AddRef(imgl); + ok(ret == 2, "Expected 2, got %d\n", ret); + ret = ImageList_Destroy((HIMAGELIST)imgl); + ok(ret == TRUE, "Expected TRUE, got %d\n", ret); + ret = IImageList_Release(imgl); + ok(ret == 0, "Expected 0, got %d\n", ret); + ret = ImageList_Destroy((HIMAGELIST)imgl); + ok(ret == FALSE, "Expected FALSE, got %d\n", ret); + + if (!pImageList_CoCreateInstance) { win_skip("Vista imagelist functions not available\n"); return;