[PATCH 1/3] winex11.drv: fix a WM_DROPFILES memory ownership ambiguity

Damjan Jovanovic damjan.jov at gmail.com
Sun May 4 22:25:34 CDT 2014


WM_DROPFILES receivers need to free the HDROP they are given with
DragFinish(), which calls GlobalFree(). So give them a private HDROP,
instead of letting them share winex11.drv's own with ambiguous
semantics. Additionally free this HDROP ourselves if PostMessageW()
fails.

Damjan Jovanovic

---
 dlls/winex11.drv/xdnd.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/dlls/winex11.drv/xdnd.c b/dlls/winex11.drv/xdnd.c
index 5d37495..e894de0 100644
--- a/dlls/winex11.drv/xdnd.c
+++ b/dlls/winex11.drv/xdnd.c
@@ -727,17 +727,20 @@ static void X11DRV_XDND_SendDropFiles(HWND hwnd)

     if (found)
     {
-        DROPFILES *lpDrop = current->data;
+        HGLOBAL dropHandle = GlobalAlloc(GMEM_FIXED, current->size);

-        if (lpDrop)
+        if (dropHandle)
         {
+            DROPFILES *lpDrop = GlobalLock(dropHandle);
             lpDrop->pt.x = XDNDxy.x;
             lpDrop->pt.y = XDNDxy.y;
-
+            memcpy(lpDrop, current->data, current->size);
             TRACE("Sending WM_DROPFILES: hWnd(0x%p) %p(%s)\n", hwnd,
                 ((char*)lpDrop) + lpDrop->pFiles,
debugstr_w((WCHAR*)(((char*)lpDrop) + lpDrop->pFiles)));
+            GlobalUnlock(dropHandle);

-            PostMessageW(hwnd, WM_DROPFILES, (WPARAM)lpDrop, 0L);
+            if (!PostMessageW(hwnd, WM_DROPFILES, (WPARAM)dropHandle, 0L))
+                GlobalFree(dropHandle);
         }
     }

@@ -761,6 +764,7 @@ static void X11DRV_XDND_FreeDragDropOp(void)
     LIST_FOR_EACH_ENTRY_SAFE(current, next, &xdndData, XDNDDATA, entry)
     {
         list_remove(&current->entry);
+        HeapFree(GetProcessHeap(), 0, current->data);
         HeapFree(GetProcessHeap(), 0, current);
     }

-- 
1.8.5.4



More information about the wine-patches mailing list