Huw Davies : ole32: Allow Clone to access the original memory block.

Alexandre Julliard julliard at winehq.org
Tue Aug 11 16:26:50 CDT 2020


Module: wine
Branch: master
Commit: 63dd8743352bdf7f1ae4f6244770a45581806126
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=63dd8743352bdf7f1ae4f6244770a45581806126

Author: Huw Davies <huw at codeweavers.com>
Date:   Tue Aug 11 12:49:52 2020 +0100

ole32: Allow Clone to access the original memory block.

Based on a patch by Dmitry Timoshkov.

Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ole32/hglobalstream.c       | 21 ++++++++++++++++-----
 dlls/ole32/tests/hglobalstream.c | 12 ------------
 2 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/dlls/ole32/hglobalstream.c b/dlls/ole32/hglobalstream.c
index e715cd8950..ee345f6293 100644
--- a/dlls/ole32/hglobalstream.c
+++ b/dlls/ole32/hglobalstream.c
@@ -51,6 +51,11 @@ struct handle_wrapper
     BOOL delete_on_release;
 };
 
+static void handle_addref(struct handle_wrapper *handle)
+{
+    InterlockedIncrement(&handle->ref);
+}
+
 static void handle_release(struct handle_wrapper *handle)
 {
     ULONG ref = InterlockedDecrement(&handle->ref);
@@ -586,15 +591,21 @@ static HRESULT WINAPI HGLOBALStreamImpl_Clone(
 		  IStream*     iface,
 		  IStream**    ppstm) /* [out] */
 {
-  HGLOBALStreamImpl* This = impl_from_IStream(iface);
+  HGLOBALStreamImpl* This = impl_from_IStream(iface), *clone;
   ULARGE_INTEGER dummy;
   LARGE_INTEGER offset;
-  HRESULT hr;
 
   TRACE(" Cloning %p (deleteOnRelease=%d seek position=%ld)\n",iface,This->handle->delete_on_release,(long)This->currentPosition.QuadPart);
-  hr = CreateStreamOnHGlobal(This->handle->hglobal, FALSE, ppstm);
-  if(FAILED(hr))
-    return hr;
+
+  *ppstm = NULL;
+
+  clone = hglobalstream_construct();
+  if (!clone) return E_OUTOFMEMORY;
+
+  *ppstm = &clone->IStream_iface;
+  handle_addref(This->handle);
+  clone->handle = This->handle;
+
   offset.QuadPart = (LONGLONG)This->currentPosition.QuadPart;
   IStream_Seek(*ppstm, offset, STREAM_SEEK_SET, &dummy);
   return S_OK;
diff --git a/dlls/ole32/tests/hglobalstream.c b/dlls/ole32/tests/hglobalstream.c
index 1825fa9c1e..87c502dc2f 100644
--- a/dlls/ole32/tests/hglobalstream.c
+++ b/dlls/ole32/tests/hglobalstream.c
@@ -579,14 +579,12 @@ static void test_IStream_Clone(void)
 
     stream_info(clone, &hmem_clone, &size, &pos);
     ok(hmem_clone == hmem, "handles should match\n");
-todo_wine
     ok(size == 13, "unexpected %d\n", size);
     ok(pos == 0, "unexpected %d\n", pos);
 
     buf[0] = 0;
     hr = IStream_Read(clone, buf, sizeof(buf), NULL);
     ok(hr == S_OK, "unexpected %#x\n", hr);
-todo_wine
     ok(!strcmp(buf, hello), "wrong stream contents\n");
 
     newsize.QuadPart = 0x8000;
@@ -600,9 +598,7 @@ todo_wine
 
     stream_info(clone, &hmem_clone, &size, &pos);
     ok(hmem_clone == hmem, "handles should match\n");
-todo_wine
     ok(size == 0x8000, "unexpected %#x\n", size);
-todo_wine
     ok(pos == 13, "unexpected %d\n", pos);
 
     IStream_Release(clone);
@@ -671,24 +667,19 @@ todo_wine
 
     newsize.QuadPart = 0x8000;
     hr = IStream_SetSize(clone, newsize);
-todo_wine
     ok(hr == S_OK, "unexpected %#x\n", hr);
 
     stream_info(clone, &hmem_clone, &size, &pos);
     ok(hmem_clone == hmem, "handles should match\n");
-todo_wine
     ok(size == 0x8000, "unexpected %#x\n", size);
     ok(pos == 0, "unexpected %d\n", pos);
 
     hr = IStream_Write(clone, hello, sizeof(hello), NULL);
-todo_wine
     ok(hr == S_OK, "unexpected %#x\n", hr);
 
     stream_info(clone, &hmem_clone, &size, &pos);
     ok(hmem_clone == hmem, "handles should match\n");
-todo_wine
     ok(size == 0x8000, "unexpected %#x\n", size);
-todo_wine
     ok(pos == 13, "unexpected %d\n", pos);
 
     offset.QuadPart = 0;
@@ -698,14 +689,11 @@ todo_wine
     buf[0] = 0;
     hr = IStream_Read(clone, buf, sizeof(buf), NULL);
     ok(hr == S_OK, "unexpected %#x\n", hr);
-todo_wine
     ok(!strcmp(buf, hello), "wrong stream contents\n");
 
     stream_info(clone, &hmem_clone, &size, &pos);
     ok(hmem_clone == hmem, "handles should match\n");
-todo_wine
     ok(size == 0x8000, "unexpected %#x\n", size);
-todo_wine
     ok(pos == 32, "unexpected %d\n", pos);
 
     ret = IStream_Release(clone);




More information about the wine-cvs mailing list