From 8dea6505e92a93156820ea24f1256f08cf2b9e8f Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Tue, 6 Dec 2022 16:35:36 +0100 Subject: Windows: fix memory leak caused by RegisterDragDrop (#569) - call RevokeDragDrop() when the window is hidden - do not delete the *static* FLDropTarget object --- src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx | 3 +++ src/fl_dnd_win32.cxx | 7 +++---- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx index 45e5cb39e..8a789bd1d 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx +++ b/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx @@ -470,6 +470,9 @@ void Fl_WinAPI_Window_Driver::hide() { return; } + // Issue #569: undo RegisterDragDrop() + RevokeDragDrop((HWND)ip->xid); + // make sure any custom icons get freed // icons(NULL, 0); // free_icons() is called by the Fl_Window destructor // this little trick keeps the current clipboard alive, even if we are about diff --git a/src/fl_dnd_win32.cxx b/src/fl_dnd_win32.cxx index 65a9a81dc..1c76558ae 100644 --- a/src/fl_dnd_win32.cxx +++ b/src/fl_dnd_win32.cxx @@ -1,7 +1,7 @@ // // Drag & Drop code for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2018 by Bill Spitzak and others. +// Copyright 1998-2022 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -54,7 +54,7 @@ Fl_Window *fl_dnd_target_window = 0; */ class FLDropTarget : public IDropTarget { - DWORD m_cRefCount; + DWORD m_cRefCount; // for "statistics" only (issue #569) DWORD lastEffect; int px, py; public: @@ -74,8 +74,7 @@ public: ULONG STDMETHODCALLTYPE Release() { long nTemp; nTemp = --m_cRefCount; - if(nTemp==0) - delete this; + // this is a static object, do not 'delete this' (issue #569) return nTemp; } HRESULT STDMETHODCALLTYPE DragEnter( IDataObject *pDataObj, DWORD /*grfKeyState*/, POINTL pt, DWORD *pdwEffect) { -- cgit v1.2.3