Vitaliy Margolen : dinput: AddRef and Release parent DirectInput class.

Alexandre Julliard julliard at wine.codeweavers.com
Sun Dec 24 09:37:55 CST 2006


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

Author: Vitaliy Margolen <wine-patches at kievinfo.com>
Date:   Fri Dec 22 10:54:29 2006 -0700

dinput: AddRef and Release parent DirectInput class.

---

 dlls/dinput/joystick_linux.c      |    4 ++--
 dlls/dinput/joystick_linuxinput.c |    4 ++++
 dlls/dinput/keyboard.c            |   10 +++++++++-
 dlls/dinput/mouse.c               |    5 +++++
 dlls/dinput/tests/keyboard.c      |    2 ++
 dlls/dinput/tests/mouse.c         |    4 +++-
 6 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c
index 745fd5c..914d05d 100644
--- a/dlls/dinput/joystick_linux.c
+++ b/dlls/dinput/joystick_linux.c
@@ -484,7 +484,7 @@ static HRESULT alloc_device(REFGUID rgui
     hr = create_DataFormat(&c_dfDIJoystick2, &newDevice->base.data_format);
     if (hr != DI_OK) goto FAILED;
 
-    IDirectInputDevice_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput);
+    IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput);
 
     newDevice->devcaps.dwSize = sizeof(newDevice->devcaps);
     newDevice->devcaps.dwFlags = DIDC_ATTACHED;
@@ -613,8 +613,8 @@ static ULONG WINAPI JoystickAImpl_Releas
     release_DataFormat(&This->base.data_format);
 
     This->base.crit.DebugInfo->Spare[0] = 0;
+    IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
     DeleteCriticalSection(&This->base.crit);
-    IDirectInputDevice_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
 
     HeapFree(GetProcessHeap(),0,This);
     return 0;
diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c
index 4cce222..b049730 100644
--- a/dlls/dinput/joystick_linuxinput.c
+++ b/dlls/dinput/joystick_linuxinput.c
@@ -393,7 +393,10 @@ static JoystickImpl *alloc_device(REFGUI
 
   /* create the default transform filter */
   if (create_DataFormat(&c_dfDIJoystick2, &newDevice->base.data_format) == DI_OK)
+  {
+    IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput);
     return newDevice;
+  }
 
   HeapFree(GetProcessHeap(),0,newDevice);
   return NULL;
@@ -491,6 +494,7 @@ static ULONG WINAPI JoystickAImpl_Releas
         /* release the data transform filter */
         release_DataFormat(&This->base.data_format);
 
+        IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
         DeleteCriticalSection(&This->base.crit);
         
         HeapFree(GetProcessHeap(),0,This);
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c
index 14562b4..4308b45 100644
--- a/dlls/dinput/keyboard.c
+++ b/dlls/dinput/keyboard.c
@@ -198,7 +198,12 @@ static SysKeyboardImpl *alloc_device(REF
 
     newDevice->base.data_format.wine_df = &c_dfDIKeyboard;
     if (create_DataFormat(&c_dfDIKeyboard, &newDevice->base.data_format) == DI_OK)
+    {
+        IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput);
         return newDevice;
+    }
+
+    HeapFree(GetProcessHeap(), 0, newDevice);
     return NULL;
 }
 
@@ -214,6 +219,7 @@ static HRESULT keyboarddev_create_device
 	IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
       *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &SysKeyboardAvt, dinput);
       TRACE("Creating a Keyboard device (%p)\n", *pdev);
+      if (!*pdev) return DIERR_OUTOFMEMORY;
       return DI_OK;
     } else
       return DIERR_NOINTERFACE;
@@ -232,6 +238,7 @@ static HRESULT keyboarddev_create_device
 	IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
       *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &SysKeyboardWvt, dinput);
       TRACE("Creating a Keyboard device (%p)\n", *pdev);
+      if (!*pdev) return DIERR_OUTOFMEMORY;
       return DI_OK;
     } else
       return DIERR_NOINTERFACE;
@@ -257,8 +264,9 @@ static ULONG WINAPI SysKeyboardAImpl_Rel
 
     set_dinput_hook(WH_KEYBOARD_LL, NULL);
 
-    DeleteCriticalSection(&This->base.crit);
     HeapFree(GetProcessHeap(), 0, This->base.data_queue);
+    IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
+    DeleteCriticalSection(&This->base.crit);
     HeapFree(GetProcessHeap(), 0, This);
 
     return DI_OK;
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c
index 9ab1b1f..7b4fef6 100644
--- a/dlls/dinput/mouse.c
+++ b/dlls/dinput/mouse.c
@@ -194,8 +194,12 @@ static SysMouseImpl *alloc_device(REFGUI
 
     newDevice->base.data_format.wine_df = &c_dfDIMouse2;
     if (create_DataFormat(&c_dfDIMouse2, &newDevice->base.data_format) == DI_OK)
+    {
+        IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput);
         return newDevice;
+    }
 
+    HeapFree(GetProcessHeap(), 0, newDevice);
     return NULL;
 }
 
@@ -270,6 +274,7 @@ static ULONG WINAPI SysMouseAImpl_Releas
 
     release_DataFormat(&This->base.data_format);
 
+    IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
     DeleteCriticalSection(&This->base.crit);
     HeapFree(GetProcessHeap(),0,This);
     return 0;
diff --git a/dlls/dinput/tests/keyboard.c b/dlls/dinput/tests/keyboard.c
index c911dcb..4503f2f 100644
--- a/dlls/dinput/tests/keyboard.c
+++ b/dlls/dinput/tests/keyboard.c
@@ -94,6 +94,8 @@ static void acquire_tests(LPDIRECTINPUT
     ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceState(10,) should have failed: %s\n", DXGetErrorString8(hr));
     hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
     ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %s\n", DXGetErrorString8(hr));
+
+    if (pKeyboard) IUnknown_Release(pKeyboard);
 }
 
 static const HRESULT SetCoop_null_window[16] =  {
diff --git a/dlls/dinput/tests/mouse.c b/dlls/dinput/tests/mouse.c
index 0743a2e..db95ab2 100644
--- a/dlls/dinput/tests/mouse.c
+++ b/dlls/dinput/tests/mouse.c
@@ -95,6 +95,7 @@ static void mouse_tests(void)
     LPDIRECTINPUT pDI = NULL;
     HINSTANCE hInstance = GetModuleHandle(NULL);
     HWND hwnd;
+    ULONG ref = 0;
 
     hr = DirectInputCreate(hInstance, DIRECTINPUT_VERSION, &pDI, NULL);
     ok(SUCCEEDED(hr), "DirectInputCreate() failed: %s\n", DXGetErrorString8(hr));
@@ -112,7 +113,8 @@ static void mouse_tests(void)
 
         DestroyWindow(hwnd);
     }
-    if (pDI) IUnknown_Release(pDI);
+    if (pDI) ref = IUnknown_Release(pDI);
+    ok(!ref, "IDirectInput_Release() reference count = %d\n", ref);
 }
 
 START_TEST(mouse)




More information about the wine-cvs mailing list