user32: Also release GMEM_FIXED data in free_cached_data. (v2)

Sebastian Lackner sebastian at fds-team.de
Sat Oct 1 07:55:05 CDT 2016


Signed-off-by: Sebastian Lackner <sebastian at fds-team.de>
---

Changes in v2:
* Keep the tests (but we have to mark them as broken on < Vista).

 dlls/user32/clipboard.c       |    6 +-----
 dlls/user32/tests/clipboard.c |   19 ++++++++++++-------
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/dlls/user32/clipboard.c b/dlls/user32/clipboard.c
index 0d48984..d33459c 100644
--- a/dlls/user32/clipboard.c
+++ b/dlls/user32/clipboard.c
@@ -326,11 +326,7 @@ static void free_cached_data( struct cached_format *cache )
         GlobalFree( cache->handle );
         break;
     default:
-        if ((ptr = GlobalLock( cache->handle )) && ptr != cache->handle)
-        {
-            GlobalUnlock( cache->handle );
-            GlobalFree( cache->handle );
-        }
+        GlobalFree( cache->handle );
         break;
     }
     list_remove( &cache->entry );
diff --git a/dlls/user32/tests/clipboard.c b/dlls/user32/tests/clipboard.c
index 832eca6..69bdba8 100644
--- a/dlls/user32/tests/clipboard.c
+++ b/dlls/user32/tests/clipboard.c
@@ -1590,9 +1590,7 @@ static BOOL is_fixed( HANDLE handle )
 
 static BOOL is_freed( HANDLE handle )
 {
-    void *ptr = GlobalLock( handle );
-    if (ptr) GlobalUnlock( handle );
-    return !ptr;
+    return !GlobalSize( handle );
 }
 
 static UINT format_id;
@@ -1602,7 +1600,8 @@ static const LOGPALETTE logpalette = { 0x300, 1, {{ 0x12, 0x34, 0x56, 0x78 }}};
 
 static void test_handles( HWND hwnd )
 {
-    HGLOBAL h, htext, htext2, htext3, htext4, htext5, hfixed, hmoveable, empty_fixed, empty_moveable;
+    HGLOBAL h, htext, htext2, htext3, htext4, htext5;
+    HGLOBAL hfixed, hfixed2, hmoveable, empty_fixed, empty_moveable;
     void *ptr;
     UINT format_id2 = RegisterClipboardFormatA( "another format" );
     BOOL r;
@@ -1622,6 +1621,7 @@ static void test_handles( HWND hwnd )
     palette = CreatePalette( &logpalette );
 
     hfixed = GlobalAlloc( GMEM_FIXED, 17 );
+    hfixed2 = GlobalAlloc( GMEM_FIXED, 17 );
     ok( is_fixed( hfixed ), "expected fixed mem %p\n", hfixed );
     ok( GlobalSize( hfixed ) == 17, "wrong size %lu\n", GlobalSize( hfixed ));
 
@@ -1682,8 +1682,8 @@ static void test_handles( HWND hwnd )
     h = SetClipboardData( format_id2, empty_fixed );
     ok( h == empty_fixed, "got %p\n", h );
     ok( is_fixed( h ), "expected fixed mem %p\n", h );
-    h = SetClipboardData( 0xdeadbeef, hfixed );
-    ok( h == hfixed, "got %p\n", h );
+    h = SetClipboardData( 0xdeadbeef, hfixed2 );
+    ok( h == hfixed2, "got %p\n", h );
     ok( is_fixed( h ), "expected fixed mem %p\n", h );
     h = SetClipboardData( 0xdeadbabe, hmoveable );
     ok( h == hmoveable, "got %p\n", h );
@@ -1719,7 +1719,7 @@ static void test_handles( HWND hwnd )
     ok( is_fixed( data ), "expected fixed mem %p\n", data );
 
     data = GetClipboardData( 0xdeadbeef );
-    ok( data == hfixed, "wrong data %p\n", data );
+    ok( data == hfixed2, "wrong data %p\n", data );
     ok( is_fixed( data ), "expected fixed mem %p\n", data );
 
     data = GetClipboardData( 0xdeadbabe );
@@ -1734,6 +1734,11 @@ static void test_handles( HWND hwnd )
     ok( is_moveable( h ), "expected moveable mem %p\n", h );
     ok( is_freed( htext5 ), "expected freed mem %p\n", htext5 );
 
+    h = SetClipboardData( 0xdeadbeef, hfixed );
+    ok( h == hfixed, "got %p\n", h );
+    ok( is_fixed( h ), "expected fixed mem %p\n", h );
+    ok( is_freed( hfixed2 ) || broken( !is_freed( hfixed2 )) /* < Vista */, "expected freed mem %p\n", hfixed2 );
+
     r = CloseClipboard();
     ok( r, "gle %d\n", GetLastError() );
 
-- 
2.9.0



More information about the wine-patches mailing list