Rémi Bernon : dinput: Allocate data format on device creation.

Alexandre Julliard julliard at winehq.org
Thu Aug 26 15:22:32 CDT 2021


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

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Wed Aug 25 18:20:25 2021 +0200

dinput: Allocate data format on device creation.

It's accessed on Release, and this will make it easier to handle device
creation failure cleanup.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dinput/device.c              | 9 +++++++++
 dlls/dinput/joystick_linux.c      | 3 +--
 dlls/dinput/joystick_linuxinput.c | 3 +--
 dlls/dinput/joystick_osx.c        | 3 +--
 dlls/dinput/keyboard.c            | 4 +---
 dlls/dinput/mouse.c               | 3 +--
 6 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c
index ac60a21326c..25084f82a9c 100644
--- a/dlls/dinput/device.c
+++ b/dlls/dinput/device.c
@@ -1708,11 +1708,20 @@ HRESULT direct_input_device_alloc( SIZE_T size, const IDirectInputDevice8WVtbl *
                                    const GUID *guid, IDirectInputImpl *dinput, void **out )
 {
     IDirectInputDeviceImpl *This;
+    DIDATAFORMAT *format;
+
     if (!(This = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size ))) return DIERR_OUTOFMEMORY;
+    if (!(format = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*format) )))
+    {
+        HeapFree( GetProcessHeap(), 0, This );
+        return DIERR_OUTOFMEMORY;
+    }
+
     This->IDirectInputDevice8A_iface.lpVtbl = &dinput_device_a_vtbl;
     This->IDirectInputDevice8W_iface.lpVtbl = vtbl;
     This->ref = 1;
     This->guid = *guid;
+    This->data_format.wine_df = format;
     InitializeCriticalSection( &This->crit );
     This->dinput = dinput;
     IDirectInput_AddRef( &dinput->IDirectInput7A_iface );
diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c
index 3215978c995..258f6e9e5e0 100644
--- a/dlls/dinput/joystick_linux.c
+++ b/dlls/dinput/joystick_linux.c
@@ -411,6 +411,7 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickIm
 
     if (FAILED(hr = direct_input_device_alloc( sizeof(JoystickImpl), &JoystickWvt, rguid, dinput, (void **)&newDevice )))
         return hr;
+    df = newDevice->generic.base.data_format.wine_df;
     newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->generic.base.crit");
 
     newDevice->joydev = &joystick_devices[index];
@@ -438,7 +439,6 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickIm
         goto FAILED1;
 
     /* Create copy of default data format */
-    if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2.dwSize))) goto FAILED;
     memcpy(df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
 
     df->dwNumObjs = newDevice->generic.devcaps.dwAxes + newDevice->generic.devcaps.dwPOVs + newDevice->generic.devcaps.dwButtons;
@@ -465,7 +465,6 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickIm
         df->rgodf[idx  ].pguid = &GUID_Button;
         df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON;
     }
-    newDevice->generic.base.data_format.wine_df = df;
 
     /* initialize default properties */
     for (i = 0; i < c_dfDIJoystick2.dwNumObjs; i++) {
diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c
index 2b970271ec3..06a735f7d91 100644
--- a/dlls/dinput/joystick_linuxinput.c
+++ b/dlls/dinput/joystick_linuxinput.c
@@ -407,6 +407,7 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickIm
 
     if (FAILED(hr = direct_input_device_alloc( sizeof(JoystickImpl), &JoystickWvt, rguid, dinput, (void **)&newDevice )))
         return hr;
+    df = newDevice->generic.base.data_format.wine_df;
     newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->base.crit");
 
     newDevice->generic.joy_polldev = joy_polldev;
@@ -468,7 +469,6 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickIm
     if (setup_dinput_options(&newDevice->generic, default_axis_map) != DI_OK) goto failed;
 
     /* Create copy of default data format */
-    if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2.dwSize))) goto failed;
     memcpy(df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
     if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed;
 
@@ -514,7 +514,6 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickIm
         df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(newDevice->generic.devcaps.dwButtons++) | DIDFT_PSHBUTTON;
     }
     df->dwNumObjs = idx;
-    newDevice->generic.base.data_format.wine_df = df;
 
     fake_current_js_state(newDevice);
 
diff --git a/dlls/dinput/joystick_osx.c b/dlls/dinput/joystick_osx.c
index 27a47b07639..62a063b6da1 100644
--- a/dlls/dinput/joystick_osx.c
+++ b/dlls/dinput/joystick_osx.c
@@ -1075,6 +1075,7 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickIm
 
     if (FAILED(hr = direct_input_device_alloc( sizeof(JoystickImpl), &JoystickWvt, rguid, dinput, (void **)&newDevice )))
         return hr;
+    df = newDevice->generic.base.data_format.wine_df;
     newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->generic.base.crit");
 
     newDevice->id = index;
@@ -1138,7 +1139,6 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickIm
     }
 
     /* Create copy of default data format */
-    if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2.dwSize))) goto FAILED;
     memcpy(df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
 
     df->dwNumObjs = newDevice->generic.devcaps.dwAxes + newDevice->generic.devcaps.dwPOVs + newDevice->generic.devcaps.dwButtons;
@@ -1203,7 +1203,6 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickIm
         df->rgodf[idx  ].pguid = &GUID_Button;
         df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON;
     }
-    newDevice->generic.base.data_format.wine_df = df;
 
     /* initialize default properties */
     get_osx_device_elements_props(newDevice);
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c
index fc9dbdb2ed4..5d532ab8059 100644
--- a/dlls/dinput/keyboard.c
+++ b/dlls/dinput/keyboard.c
@@ -203,12 +203,12 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysKeyboar
 
     if (FAILED(hr = direct_input_device_alloc( sizeof(SysKeyboardImpl), &SysKeyboardWvt, rguid, dinput, (void **)&newDevice )))
         return hr;
+    df = newDevice->base.data_format.wine_df;
     newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysKeyboardImpl*->base.crit");
 
     newDevice->subtype = get_keyboard_subtype();
 
     /* Create copy of default data format */
-    if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIKeyboard.dwSize))) goto failed;
     memcpy(df, &c_dfDIKeyboard, c_dfDIKeyboard.dwSize);
     if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed;
 
@@ -226,8 +226,6 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysKeyboar
     }
     df->dwNumObjs = idx;
 
-    newDevice->base.data_format.wine_df = df;
-
     *out = newDevice;
     return DI_OK;
 
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c
index 22e40a60285..145a792f396 100644
--- a/dlls/dinput/mouse.c
+++ b/dlls/dinput/mouse.c
@@ -149,6 +149,7 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysMouseIm
 
     if (FAILED(hr = direct_input_device_alloc( sizeof(SysMouseImpl), &SysMouseWvt, rguid, dinput, (void **)&newDevice )))
         return hr;
+    df = newDevice->base.data_format.wine_df;
     newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysMouseImpl*->base.crit");
 
     newDevice->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
@@ -165,7 +166,6 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysMouseIm
     if (hkey) RegCloseKey(hkey);
 
     /* Create copy of default data format */
-    if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIMouse2.dwSize))) goto failed;
     memcpy(df, &c_dfDIMouse2, c_dfDIMouse2.dwSize);
     if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed;
     memcpy(df->rgodf, c_dfDIMouse2.rgodf, df->dwNumObjs * df->dwObjSize);
@@ -177,7 +177,6 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysMouseIm
         else
             df->rgodf[i].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON;
 
-    newDevice->base.data_format.wine_df = df;
     if (dinput->dwVersion >= 0x0800)
     {
         newDevice->base.use_raw_input = TRUE;




More information about the wine-cvs mailing list