[PATCH 5/6] ole32: Allow Clone to access the original memory block.

Huw Davies huw at codeweavers.com
Tue Aug 11 06:49:52 CDT 2020


Based on a patch by Dmitry Timoshkov.

Signed-off-by: Huw Davies <huw at codeweavers.com>
---
 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 e715cd89500..ee345f6293a 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 1825fa9c1e4..87c502dc2f4 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);
-- 
2.23.0




More information about the wine-devel mailing list