Zebediah Figura : rpcrt4: Avoid reference leaks when unmarshalling [in, out] pointers.

Alexandre Julliard julliard at winehq.org
Fri Nov 2 18:03:19 CDT 2018


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

Author: Zebediah Figura <z.figura12 at gmail.com>
Date:   Thu Nov  1 23:53:45 2018 -0500

rpcrt4: Avoid reference leaks when unmarshalling [in, out] pointers.

Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/rpcrt4/ndr_ole.c            | 10 ++++++++--
 dlls/rpcrt4/tests/ndr_marshall.c |  2 --
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/dlls/rpcrt4/ndr_ole.c b/dlls/rpcrt4/ndr_ole.c
index 8608691..c8026c0 100644
--- a/dlls/rpcrt4/ndr_ole.c
+++ b/dlls/rpcrt4/ndr_ole.c
@@ -338,19 +338,25 @@ unsigned char * WINAPI NdrInterfacePointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg
                                                     PFORMAT_STRING pFormat,
                                                     unsigned char fMustAlloc)
 {
+  IUnknown **unk = (IUnknown **)ppMemory;
   LPSTREAM stream;
   HRESULT hr;
 
   TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);
   if (!LoadCOM()) return NULL;
-  *(LPVOID*)ppMemory = NULL;
+
+  /* Avoid reference leaks for [in, out] pointers. */
+  if (pStubMsg->IsClient && *unk)
+    IUnknown_Release(*unk);
+
+  *unk = NULL;
   if (pStubMsg->Buffer + sizeof(DWORD) < (unsigned char *)pStubMsg->RpcMsg->Buffer + pStubMsg->BufferLength) {
     ULONG size;
 
     hr = RpcStream_Create(pStubMsg, FALSE, &size, &stream);
     if (hr == S_OK) {
       if (size != 0)
-        hr = COM_UnmarshalInterface(stream, &IID_NULL, (LPVOID*)ppMemory);
+        hr = COM_UnmarshalInterface(stream, &IID_NULL, (void **)unk);
 
       IStream_Release(stream);
     }
diff --git a/dlls/rpcrt4/tests/ndr_marshall.c b/dlls/rpcrt4/tests/ndr_marshall.c
index 5da03e2..d436b42 100644
--- a/dlls/rpcrt4/tests/ndr_marshall.c
+++ b/dlls/rpcrt4/tests/ndr_marshall.c
@@ -1327,9 +1327,7 @@ static void test_iface_ptr(void)
     ok(!my_alloc_called, "alloc called %d\n", my_alloc_called);
     ok(!my_free_called, "free called %d\n", my_free_called);
     ok(server_obj.ref > 1, "got %d references\n", server_obj.ref);
-todo_wine
     ok(client_obj.ref == 1, "got %d references\n", client_obj.ref);
-client_obj.ref = 1;
 
     hr = IPersist_GetClassID(proxy, &clsid);
     ok(hr == S_OK, "got hr %#x\n", hr);




More information about the wine-cvs mailing list