Markus Stockhausen : dinput8: Ensure balance of CoInitialize/CoUninitialize .

Alexandre Julliard julliard at winehq.org
Thu Oct 15 08:54:27 CDT 2009


Module: wine
Branch: master
Commit: 70ae1ba4b552be732a5f627f62ec3521c4234988
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=70ae1ba4b552be732a5f627f62ec3521c4234988

Author: Markus Stockhausen <markus.stockhausen at collogia.de>
Date:   Wed Oct 14 19:47:45 2009 +0200

dinput8: Ensure balance of CoInitialize/CoUninitialize.

---

 dlls/dinput8/dinput8_main.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/dlls/dinput8/dinput8_main.c b/dlls/dinput8/dinput8_main.c
index 77f7f64..87dd07b 100644
--- a/dlls/dinput8/dinput8_main.c
+++ b/dlls/dinput8/dinput8_main.c
@@ -51,7 +51,7 @@ static void UnlockModule(void)
  *	DirectInput8Create (DINPUT8.@)
  */
 HRESULT WINAPI DECLSPEC_HOTPATCH DirectInput8Create(HINSTANCE hinst, DWORD dwVersion, REFIID riid, LPVOID *ppDI, LPUNKNOWN punkOuter) {
-    HRESULT hr;
+    HRESULT hr, hrCo;
 
     TRACE("hInst (%p), dwVersion: %d, riid (%s), punkOuter (%p))\n", hinst, dwVersion, debugstr_guid(riid), punkOuter);
 
@@ -62,7 +62,7 @@ HRESULT WINAPI DECLSPEC_HOTPATCH DirectInput8Create(HINSTANCE hinst, DWORD dwVer
     if( !(IsEqualGUID(&IID_IDirectInput8A, riid) || IsEqualGUID(&IID_IDirectInput8W, riid) || IsEqualGUID(&IID_IUnknown, riid)) )
         return DIERR_INVALIDPARAM;
 
-    CoInitialize(NULL);
+    hrCo = CoInitialize(NULL);
     
     hr = CoCreateInstance( &CLSID_DirectInput8, punkOuter, CLSCTX_INPROC_SERVER, riid, ppDI);
     if(FAILED(hr)) {
@@ -70,7 +70,9 @@ HRESULT WINAPI DECLSPEC_HOTPATCH DirectInput8Create(HINSTANCE hinst, DWORD dwVer
         return DIERR_INVALIDPARAM;
     }
 
-    CoUninitialize();
+    /*  ensure balance of calls */
+    if(hrCo == S_OK || hrCo == S_FALSE)
+        CoUninitialize();
 
     /* When aggregation is used (punkOuter!=NULL) the application needs to manually call Initialize. */
     if(punkOuter == NULL && IsEqualGUID(&IID_IDirectInput8A, riid)) {




More information about the wine-cvs mailing list