From 0d481950f96f05236060fa0d36bd6fcc737f01bd Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 13 Sep 2018 10:18:00 +0100 Subject: [PATCH] Windows: Fix a leak due to the IDropTarget interface ref count not being decremented for child HWNDs after the parent HWND is destroyed --- .../native/juce_win32_Windowing.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp index 3bce73ba85..5323f2639a 100644 --- a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp @@ -2132,10 +2132,22 @@ private: } } + static BOOL CALLBACK revokeChildDragDropCallback (HWND hwnd, LPARAM) { RevokeDragDrop (hwnd); return TRUE; } + static void* destroyWindowCallback (void* handle) { - RevokeDragDrop ((HWND) handle); - DestroyWindow ((HWND) handle); + auto hwnd = reinterpret_cast (handle); + + if (IsWindow (hwnd)) + { + RevokeDragDrop (hwnd); + + // NB: we need to do this before DestroyWindow() as child HWNDs will be invalid after + EnumChildWindows (hwnd, revokeChildDragDropCallback, 0); + + DestroyWindow (hwnd); + } + return nullptr; }