Nikolay Sivov : wbemprox: Keep context object per services instance.

Alexandre Julliard julliard at winehq.org
Wed Mar 3 15:47:28 CST 2021


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

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Wed Mar  3 09:05:48 2021 +0300

wbemprox: Keep context object per services instance.

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Hans Leidekker <hans at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/wbemprox/services.c         | 12 ++++++++----
 dlls/wbemprox/tests/services.c   | 24 ++++++++++++++++++++++++
 dlls/wbemprox/wbemlocator.c      |  6 +++---
 dlls/wbemprox/wbemprox_private.h |  2 +-
 4 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/dlls/wbemprox/services.c b/dlls/wbemprox/services.c
index eff5148ef29..19e03fa152b 100644
--- a/dlls/wbemprox/services.c
+++ b/dlls/wbemprox/services.c
@@ -210,6 +210,7 @@ struct wbem_services
     CRITICAL_SECTION cs;
     WCHAR *namespace;
     struct async_header *async;
+    IWbemContext *context;
 };
 
 static inline struct wbem_services *impl_from_IWbemServices( IWbemServices *iface )
@@ -243,6 +244,8 @@ static ULONG WINAPI wbem_services_Release(
         }
         ws->cs.DebugInfo->Spare[0] = 0;
         DeleteCriticalSection( &ws->cs );
+        if (ws->context)
+            IWbemContext_Release( ws->context );
         heap_free( ws->namespace );
         heap_free( ws );
     }
@@ -293,7 +296,7 @@ static HRESULT WINAPI wbem_services_OpenNamespace(
     if ((wcsicmp( strNamespace, L"cimv2" ) && wcsicmp( strNamespace, L"default" )) || ws->namespace)
         return WBEM_E_INVALID_NAMESPACE;
 
-    return WbemServices_create( L"cimv2", (void **)ppWorkingNamespace );
+    return WbemServices_create( L"cimv2", NULL, (void **)ppWorkingNamespace );
 }
 
 static HRESULT WINAPI wbem_services_CancelAsyncCall(
@@ -933,21 +936,22 @@ static const IWbemServicesVtbl wbem_services_vtbl =
     wbem_services_ExecMethodAsync
 };
 
-HRESULT WbemServices_create( const WCHAR *namespace, LPVOID *ppObj )
+HRESULT WbemServices_create( const WCHAR *namespace, IWbemContext *context, LPVOID *ppObj )
 {
     struct wbem_services *ws;
 
     TRACE("(%p)\n", ppObj);
 
-    ws = heap_alloc( sizeof(*ws) );
+    ws = heap_alloc_zero( sizeof(*ws) );
     if (!ws) return E_OUTOFMEMORY;
 
     ws->IWbemServices_iface.lpVtbl = &wbem_services_vtbl;
     ws->refs      = 1;
     ws->namespace = heap_strdupW( namespace );
-    ws->async     = NULL;
     InitializeCriticalSection( &ws->cs );
     ws->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": wbemprox_services.cs");
+    if (context)
+        IWbemContext_Clone( context, &ws->context );
 
     *ppObj = &ws->IWbemServices_iface;
 
diff --git a/dlls/wbemprox/tests/services.c b/dlls/wbemprox/tests/services.c
index ebbc766d6c5..da985de01fa 100644
--- a/dlls/wbemprox/tests/services.c
+++ b/dlls/wbemprox/tests/services.c
@@ -24,6 +24,15 @@
 #include "wbemcli.h"
 #include "wine/test.h"
 
+#define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
+static void _expect_ref(IUnknown* obj, ULONG ref, int line)
+{
+    ULONG rc;
+    IUnknown_AddRef(obj);
+    rc = IUnknown_Release(obj);
+    ok_(__FILE__,line)(rc == ref, "expected refcount %d, got %d\n", ref, rc);
+}
+
 static void test_IClientSecurity(void)
 {
     HRESULT hr;
@@ -124,6 +133,7 @@ static void test_IWbemLocator(void)
     };
     IWbemLocator *locator;
     IWbemServices *services;
+    IWbemContext *context;
     unsigned int i;
     HRESULT hr;
     BSTR resource;
@@ -146,6 +156,20 @@ static void test_IWbemLocator(void)
         SysFreeString( resource );
         if (hr == S_OK) IWbemServices_Release( services );
     }
+
+    hr = CoCreateInstance( &CLSID_WbemContext, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemContext, (void **)&context );
+    ok(hr == S_OK, "Failed to create context object, hr %#x.\n", hr);
+
+    EXPECT_REF(context, 1);
+    resource = SysAllocString( L"root\\default" );
+    hr = IWbemLocator_ConnectServer( locator, resource, NULL, NULL, NULL, 0, NULL, context, &services );
+    ok(hr == S_OK, "Failed to connect, hr %#x.\n", hr);
+    SysFreeString( resource );
+    EXPECT_REF(context, 1);
+    IWbemServices_Release( services );
+
+    IWbemContext_Release( context );
+
     IWbemLocator_Release( locator );
 }
 
diff --git a/dlls/wbemprox/wbemlocator.c b/dlls/wbemprox/wbemlocator.c
index 9b6f2cbc741..5e86f2be86d 100644
--- a/dlls/wbemprox/wbemlocator.c
+++ b/dlls/wbemprox/wbemlocator.c
@@ -161,14 +161,14 @@ static HRESULT WINAPI wbem_locator_ConnectServer(
     const BSTR Locale,
     LONG SecurityFlags,
     const BSTR Authority,
-    IWbemContext *pCtx,
+    IWbemContext *context,
     IWbemServices **ppNamespace)
 {
     HRESULT hr;
     WCHAR *server, *namespace;
 
     TRACE("%p, %s, %s, %s, %s, 0x%08x, %s, %p, %p)\n", iface, debugstr_w(NetworkResource), debugstr_w(User),
-          debugstr_w(Password), debugstr_w(Locale), SecurityFlags, debugstr_w(Authority), pCtx, ppNamespace);
+          debugstr_w(Password), debugstr_w(Locale), SecurityFlags, debugstr_w(Authority), context, ppNamespace);
 
     hr = parse_resource( NetworkResource, &server, &namespace );
     if (hr != S_OK) return hr;
@@ -187,7 +187,7 @@ static HRESULT WINAPI wbem_locator_ConnectServer(
     if (SecurityFlags)
         FIXME("unsupported flags\n");
 
-    hr = WbemServices_create( namespace, (void **)ppNamespace );
+    hr = WbemServices_create( namespace, context, (void **)ppNamespace );
     heap_free( namespace );
     heap_free( server );
     if (SUCCEEDED( hr ))
diff --git a/dlls/wbemprox/wbemprox_private.h b/dlls/wbemprox/wbemprox_private.h
index bae4b5d20c5..7e1efe65874 100644
--- a/dlls/wbemprox/wbemprox_private.h
+++ b/dlls/wbemprox/wbemprox_private.h
@@ -236,7 +236,7 @@ HRESULT create_signature( const WCHAR *, const WCHAR *, enum param_direction,
                           IWbemClassObject ** ) DECLSPEC_HIDDEN;
 
 HRESULT WbemLocator_create(LPVOID *) DECLSPEC_HIDDEN;
-HRESULT WbemServices_create(const WCHAR *, LPVOID *) DECLSPEC_HIDDEN;
+HRESULT WbemServices_create(const WCHAR *, IWbemContext *, LPVOID *) DECLSPEC_HIDDEN;
 HRESULT WbemContext_create(void **) DECLSPEC_HIDDEN;
 HRESULT create_class_object(const WCHAR *, IEnumWbemClassObject *, UINT,
                             struct record *, IWbemClassObject **) DECLSPEC_HIDDEN;




More information about the wine-cvs mailing list