shell32/shellview: Don't crash on ::DragLeave called without droptraget.
authorNikolay Sivov <nsivov@codeweavers.com>
Thu, 11 Mar 2010 14:39:48 +0000 (17:39 +0300)
committerAlexandre Julliard <julliard@winehq.org>
Mon, 15 Mar 2010 13:18:06 +0000 (14:18 +0100)
dlls/shell32/shlview.c
dlls/shell32/tests/shlview.c

index cf9098281c092a79232b098d73570fde77905b38..7809344f4ae5234840f076f66add52e66577b0a1 100644 (file)
@@ -2407,17 +2407,25 @@ static HRESULT WINAPI ISVDropTarget_DragOver(IDropTarget *iface, DWORD grfKeySta
     return drag_notify_subitem(This, grfKeyState, pt, pdwEffect);
 }
 
-static HRESULT WINAPI ISVDropTarget_DragLeave(IDropTarget *iface) {
+static HRESULT WINAPI ISVDropTarget_DragLeave(IDropTarget *iface)
+{
     IShellViewImpl *This = impl_from_IDropTarget(iface);
 
-    IDropTarget_DragLeave(This->pCurDropTarget);
+    if (This->pCurDropTarget)
+    {
+        IDropTarget_DragLeave(This->pCurDropTarget);
+        IDropTarget_Release(This->pCurDropTarget);
+        This->pCurDropTarget = NULL;
+    }
+
+    if (This->pCurDataObject)
+    {
+        IDataObject_Release(This->pCurDataObject);
+        This->pCurDataObject = NULL;
+    }
 
-    IDropTarget_Release(This->pCurDropTarget);
-    IDataObject_Release(This->pCurDataObject);
-    This->pCurDataObject = NULL;
-    This->pCurDropTarget = NULL;
     This->iDragOverItem = 0;
-     
+
     return S_OK;
 }
 
index ac603c11bdc31691c7b06a57eaf1db2dfe96351d..31f47c1bb726cff3226996bb230bd047f9feef46 100644 (file)
@@ -318,6 +318,7 @@ static void test_IShellView_CreateViewWindow(void)
     IShellFolder *desktop;
     FOLDERSETTINGS settings;
     IShellView *view;
+    IDropTarget *dt;
     HWND hwnd_view;
     HRESULT hr;
     RECT r = {0};
@@ -346,6 +347,13 @@ if (0)
     ok(hr == E_UNEXPECTED, "got (0x%08x)\n", hr);
     ok(hwnd_view == 0, "got %p\n", hwnd_view);
 
+    /* ::DragLeave without drag operation */
+    hr = IShellView_QueryInterface(view, &IID_IDropTarget, (void**)&dt);
+    ok(hr == S_OK, "got (0x%08x)\n", hr);
+    hr = IDropTarget_DragLeave(dt);
+    ok(hr == S_OK, "got (0x%08x)\n", hr);
+    IDropTarget_Release(dt);
+
     IShellView_Release(view);
     IShellFolder_Release(desktop);
 }