[PATCH 6/6] dinput: Use msvcrt memory allocation functions.

Rémi Bernon rbernon at codeweavers.com
Mon Oct 11 03:11:00 CDT 2021


Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/dinput/ansi.c         | 42 ++++++++++++-----------
 dlls/dinput/config.c       | 12 +++----
 dlls/dinput/device.c       | 69 ++++++++++++++++++--------------------
 dlls/dinput/dinput_main.c  | 17 ++++------
 dlls/dinput/joystick_hid.c | 39 +++++++++++----------
 dlls/dinput/keyboard.c     |  8 ++---
 dlls/dinput/mouse.c        |  8 ++---
 7 files changed, 95 insertions(+), 100 deletions(-)

diff --git a/dlls/dinput/ansi.c b/dlls/dinput/ansi.c
index cbc9dbc9733..3d2d82b0f36 100644
--- a/dlls/dinput/ansi.c
+++ b/dlls/dinput/ansi.c
@@ -129,7 +129,7 @@ static HRESULT string_atow( const char *in, WCHAR **out )
     if (!in) return DI_OK;
 
     len = MultiByteToWideChar( CP_ACP, 0, in, -1, NULL, 0 );
-    if (!(*out = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return DIERR_OUTOFMEMORY;
+    if (!(*out = malloc( len * sizeof(WCHAR) ))) return DIERR_OUTOFMEMORY;
 
     MultiByteToWideChar( CP_ACP, 0, in, -1, *out, len );
     return DI_OK;
@@ -252,7 +252,7 @@ static HRESULT diconfiguredevicesparams_atow( const DICONFIGUREDEVICESPARAMSA *i
         len_a = name_a - in->lptszUserNames + 1;
         len_w = MultiByteToWideChar( CP_ACP, 0, in->lptszUserNames, len_a, NULL, 0 );
 
-        out->lptszUserNames = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, len_w * sizeof(WCHAR) );
+        out->lptszUserNames = calloc( len_w, sizeof(WCHAR) );
         if (!out->lptszUserNames) return DIERR_OUTOFMEMORY;
 
         MultiByteToWideChar( CP_ACP, 0, in->lptszUserNames, len_a, out->lptszUserNames, len_w );
@@ -572,17 +572,17 @@ static HRESULT WINAPI dinput_device_a_BuildActionMap( IDirectInputDevice8A *ifac
     if (FAILED(hr = string_atow( username_a, &username_w ))) return hr;
 
     format_w.dwNumActions = format_a->dwNumActions;
-    format_w.rgoAction = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, format_a->dwNumActions * sizeof(DIACTIONW) );
+    format_w.rgoAction = calloc( format_a->dwNumActions, sizeof(DIACTIONW) );
     if (!format_w.rgoAction) hr = DIERR_OUTOFMEMORY;
     else
     {
         diactionformat_atow( format_a, &format_w, FALSE );
         hr = IDirectInputDevice8_BuildActionMap( iface_w, &format_w, username_w, flags );
         diactionformat_wtoa( &format_w, format_a );
-        HeapFree( GetProcessHeap(), 0, format_w.rgoAction );
+        free( format_w.rgoAction );
     }
 
-    HeapFree( GetProcessHeap(), 0, username_w );
+    free( username_w );
     return hr;
 }
 
@@ -601,17 +601,17 @@ static HRESULT WINAPI dinput_device_a_SetActionMap( IDirectInputDevice8A *iface_
     if (FAILED(hr = string_atow( username_a, &username_w ))) return hr;
 
     format_w.dwNumActions = format_a->dwNumActions;
-    format_w.rgoAction = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, format_a->dwNumActions * sizeof(DIACTIONW) );
+    format_w.rgoAction = calloc( format_a->dwNumActions, sizeof(DIACTIONW) );
     if (!format_w.rgoAction) hr = DIERR_OUTOFMEMORY;
     else
     {
         diactionformat_atow( format_a, &format_w, FALSE );
         hr = IDirectInputDevice8_SetActionMap( iface_w, &format_w, username_w, flags );
         diactionformat_wtoa( &format_w, format_a );
-        HeapFree( GetProcessHeap(), 0, format_w.rgoAction );
+        free( format_w.rgoAction );
     }
 
-    HeapFree( GetProcessHeap(), 0, username_w );
+    free( username_w );
     return hr;
 }
 
@@ -627,12 +627,12 @@ static HRESULT WINAPI dinput_device_a_GetImageInfo( IDirectInputDevice8A *iface_
     if (header_a->dwSizeImageInfo != sizeof(DIDEVICEIMAGEINFOA)) return DIERR_INVALIDPARAM;
 
     header_w.dwBufferSize = (header_a->dwBufferSize / sizeof(DIDEVICEIMAGEINFOA)) * sizeof(DIDEVICEIMAGEINFOW);
-    header_w.lprgImageInfoArray = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, header_w.dwBufferSize );
+    header_w.lprgImageInfoArray = calloc( header_w.dwBufferSize, 1 );
     if (!header_w.lprgImageInfoArray) return DIERR_OUTOFMEMORY;
 
     hr = IDirectInputDevice8_GetImageInfo( iface_w, &header_w );
     dideviceimageinfoheader_wtoa( &header_w, header_a );
-    HeapFree( GetProcessHeap(), 0, header_w.lprgImageInfoArray );
+    free( header_w.lprgImageInfoArray );
     return hr;
 }
 
@@ -770,7 +770,7 @@ static HRESULT WINAPI dinput8_a_FindDevice( IDirectInput8A *iface_a, REFGUID gui
     if (FAILED(hr = string_atow( name_a, &name_w ))) return hr;
 
     hr = IDirectInput8_FindDevice( iface_w, guid, name_w, instance_guid );
-    HeapFree( GetProcessHeap(), 0, name_w );
+    free( name_w );
     return hr;
 }
 
@@ -805,17 +805,17 @@ static HRESULT WINAPI dinput8_a_EnumDevicesBySemantics( IDirectInput8A *iface_a,
     if (FAILED(hr = string_atow( username_a, &username_w ))) return hr;
 
     format_w.dwNumActions = format_a->dwNumActions;
-    format_w.rgoAction = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, format_a->dwNumActions * sizeof(DIACTIONW) );
+    format_w.rgoAction = calloc( format_a->dwNumActions, sizeof(DIACTIONW) );
     if (!format_w.rgoAction) hr = DIERR_OUTOFMEMORY;
     else
     {
         diactionformat_atow( format_a, &format_w, FALSE );
         hr = IDirectInput8_EnumDevicesBySemantics( iface_w, username_w, &format_w, enum_devices_by_semantics_wtoa_callback,
                                                    &params, flags );
-        HeapFree( GetProcessHeap(), 0, format_w.rgoAction );
+        free( format_w.rgoAction );
     }
 
-    HeapFree( GetProcessHeap(), 0, username_w );
+    free( username_w );
     return hr;
 }
 
@@ -834,7 +834,7 @@ static HRESULT WINAPI dinput8_a_ConfigureDevices( IDirectInput8A *iface_a, LPDIC
     if (FAILED(hr = diconfiguredevicesparams_atow( params_a, &params_w ))) return hr;
 
     format_w.dwNumActions = format_a->dwNumActions;
-    format_w.rgoAction = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, format_a->dwNumActions * sizeof(DIACTIONW) );
+    format_w.rgoAction = calloc( format_a->dwNumActions, sizeof(DIACTIONW) );
     if (!format_w.rgoAction) hr = DIERR_OUTOFMEMORY;
     else
     {
@@ -843,11 +843,15 @@ static HRESULT WINAPI dinput8_a_ConfigureDevices( IDirectInput8A *iface_a, LPDIC
 
         if (SUCCEEDED(hr)) hr = IDirectInput8_ConfigureDevices( iface_w, callback, &params_w, flags, ref );
 
-        if (!format_w.hInstString) for (i = 0; i < format_w.dwNumActions; ++i) HeapFree( GetProcessHeap(), 0, (void *)format_w.rgoAction[i].lptszActionName );
-        HeapFree( GetProcessHeap(), 0, format_w.rgoAction );
+        if (!format_w.hInstString)
+        {
+            for (i = 0; i < format_w.dwNumActions; ++i)
+                free( (void *)format_w.rgoAction[i].lptszActionName );
+        }
+        free( format_w.rgoAction );
     }
 
-    HeapFree( GetProcessHeap(), 0, params_w.lptszUserNames );
+    free( params_w.lptszUserNames );
     return hr;
 }
 
@@ -946,7 +950,7 @@ static HRESULT WINAPI dinput7_a_FindDevice( IDirectInput7A *iface_a, REFGUID gui
     if (FAILED(hr = string_atow( name_a, &name_w ))) return hr;
 
     hr = IDirectInput7_FindDevice( iface_w, guid, name_w, instance_guid );
-    HeapFree( GetProcessHeap(), 0, name_w );
+    free( name_w );
     return hr;
 }
 
diff --git a/dlls/dinput/config.c b/dlls/dinput/config.c
index 01a92e54bd4..8cc73c80242 100644
--- a/dlls/dinput/config.c
+++ b/dlls/dinput/config.c
@@ -190,7 +190,7 @@ static void init_devices(HWND dialog, IDirectInput8W *lpDI, DIDevicesData *data,
     IDirectInput8_EnumDevicesBySemantics(lpDI, NULL, lpdiaf, count_devices, (LPVOID) data, 0);
 
     /* Allocate devices */
-    data->devices = HeapAlloc(GetProcessHeap(), 0, sizeof(DeviceData) * data->ndevices);
+    data->devices = malloc( sizeof(DeviceData) * data->ndevices );
 
     /* Collect and insert */
     data->ndevices = 0;
@@ -210,11 +210,11 @@ static void destroy_data(HWND dialog)
     for (i=0; i < devices_data->ndevices; i++)
         IDirectInputDevice8_Release(devices_data->devices[i].lpdid);
 
-    HeapFree(GetProcessHeap(), 0, devices_data->devices);
+    free( devices_data->devices );
 
     /* Free the backup LPDIACTIONFORMATW  */
-    HeapFree(GetProcessHeap(), 0, data->original_lpdiaf->rgoAction);
-    HeapFree(GetProcessHeap(), 0, data->original_lpdiaf);
+    free( data->original_lpdiaf->rgoAction );
+    free( data->original_lpdiaf );
 }
 
 static void fill_device_object_list(HWND dialog)
@@ -365,9 +365,9 @@ static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM w
             init_listview_columns(dialog);
 
             /* Create a backup action format for CANCEL and RESET operations */
-            data->original_lpdiaf = HeapAlloc(GetProcessHeap(), 0, sizeof(*data->original_lpdiaf));
+            data->original_lpdiaf = malloc( sizeof(*data->original_lpdiaf) );
             data->original_lpdiaf->dwNumActions = data->lpdiaf->dwNumActions;
-            data->original_lpdiaf->rgoAction = HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW)*data->lpdiaf->dwNumActions);
+            data->original_lpdiaf->rgoAction = malloc( sizeof(DIACTIONW) * data->lpdiaf->dwNumActions );
             copy_actions(data->original_lpdiaf, data->lpdiaf);
 
             /* Select the first device and show its actions */
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c
index 8af593c6ff5..d8bb5e84417 100644
--- a/dlls/dinput/device.c
+++ b/dlls/dinput/device.c
@@ -436,11 +436,11 @@ static void release_DataFormat( DataFormat *format )
 {
     TRACE("Deleting DataFormat: %p\n", format);
 
-    HeapFree(GetProcessHeap(), 0, format->dt);
+    free( format->dt );
     format->dt = NULL;
-    HeapFree(GetProcessHeap(), 0, format->offsets);
+    free( format->offsets );
     format->offsets = NULL;
-    HeapFree(GetProcessHeap(), 0, format->user_df);
+    free( format->user_df );
     format->user_df = NULL;
 }
 
@@ -483,15 +483,12 @@ static HRESULT create_DataFormat(LPCDIDATAFORMAT asked_format, DataFormat *forma
     DWORD next = 0;
 
     if (!format->wine_df) return DIERR_INVALIDPARAM;
-    done = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, asked_format->dwNumObjs * sizeof(int));
-    dt = HeapAlloc(GetProcessHeap(), 0, asked_format->dwNumObjs * sizeof(DataTransform));
+    done = calloc( asked_format->dwNumObjs, sizeof(int) );
+    dt = malloc( asked_format->dwNumObjs * sizeof(DataTransform) );
     if (!dt || !done) goto failed;
 
-    if (!(format->offsets = HeapAlloc(GetProcessHeap(), 0, format->wine_df->dwNumObjs * sizeof(int))))
-        goto failed;
-
-    if (!(format->user_df = HeapAlloc(GetProcessHeap(), 0, asked_format->dwSize)))
-        goto failed;
+    if (!(format->offsets = malloc( format->wine_df->dwNumObjs * sizeof(int) ))) goto failed;
+    if (!(format->user_df = malloc( asked_format->dwSize ))) goto failed;
     memcpy(format->user_df, asked_format, asked_format->dwSize);
 
     TRACE("Creating DataTransform :\n");
@@ -595,22 +592,22 @@ static HRESULT create_DataFormat(LPCDIDATAFORMAT asked_format, DataFormat *forma
     format->internal_format_size = format->wine_df->dwDataSize;
     format->size = index;
     if (same) {
-	HeapFree(GetProcessHeap(), 0, dt);
+        free( dt );
         dt = NULL;
     }
     format->dt = dt;
 
-    HeapFree(GetProcessHeap(), 0, done);
+    free( done );
 
     return DI_OK;
 
 failed:
-    HeapFree(GetProcessHeap(), 0, done);
-    HeapFree(GetProcessHeap(), 0, dt);
+    free( done );
+    free( dt );
     format->dt = NULL;
-    HeapFree(GetProcessHeap(), 0, format->offsets);
+    free( format->offsets );
     format->offsets = NULL;
-    HeapFree(GetProcessHeap(), 0, format->user_df);
+    free( format->user_df );
     format->user_df = NULL;
 
     return DIERR_OUTOFMEMORY;
@@ -691,14 +688,14 @@ static HKEY get_mapping_key(const WCHAR *device, const WCHAR *username, const WC
     WCHAR *keyname;
 
     SIZE_T len = wcslen( subkey ) + wcslen( username ) + wcslen( device ) + wcslen( guid ) + 1;
-    keyname = HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR) * len );
+    keyname = malloc( sizeof(WCHAR) * len );
     swprintf( keyname, len, subkey, username, device, guid );
 
     /* The key used is HKCU\Software\Wine\DirectInput\Mappings\[username]\[device]\[mapping_guid] */
     if (RegCreateKeyW(HKEY_CURRENT_USER, keyname, &hkey))
         hkey = 0;
 
-    HeapFree(GetProcessHeap(), 0, keyname);
+    free( keyname );
 
     return hkey;
 }
@@ -798,7 +795,7 @@ static BOOL set_app_data(IDirectInputDeviceImpl *dev, int offset, UINT_PTR app_d
     if (num_actions == 0)
     {
         num_actions = 1;
-        action_map = HeapAlloc(GetProcessHeap(), 0, sizeof(ActionMap));
+        action_map = malloc( sizeof(ActionMap) );
         if (!action_map) return FALSE;
         target_map = &action_map[0];
     }
@@ -815,7 +812,7 @@ static BOOL set_app_data(IDirectInputDeviceImpl *dev, int offset, UINT_PTR app_d
         if (!target_map)
         {
             num_actions++;
-            action_map = HeapReAlloc(GetProcessHeap(), 0, action_map, sizeof(ActionMap)*num_actions);
+            action_map = realloc( action_map, sizeof(ActionMap) * num_actions );
             if (!action_map) return FALSE;
             target_map = &action_map[num_actions-1];
         }
@@ -921,11 +918,11 @@ HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, L
     if (num_actions == 0) return DI_NOEFFECT;
 
     /* Construct the dataformat and actionmap */
-    obj_df = HeapAlloc(GetProcessHeap(), 0, sizeof(DIOBJECTDATAFORMAT)*num_actions);
+    obj_df = malloc( sizeof(DIOBJECTDATAFORMAT) * num_actions );
     data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df;
     data_format.dwNumObjs = num_actions;
 
-    action_map = HeapAlloc(GetProcessHeap(), 0, sizeof(ActionMap)*num_actions);
+    action_map = malloc( sizeof(ActionMap) * num_actions );
 
     for (i = 0; i < lpdiaf->dwNumActions; i++)
     {
@@ -956,7 +953,7 @@ HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, L
     This->action_map = action_map;
     This->num_actions = num_actions;
 
-    HeapFree(GetProcessHeap(), 0, obj_df);
+    free( obj_df );
 
     /* Set the device properties according to the action format */
     dpr.diph.dwSize = sizeof(DIPROPRANGE);
@@ -1121,7 +1118,7 @@ HRESULT WINAPI IDirectInputDevice2WImpl_SetDataFormat(LPDIRECTINPUTDEVICE8W ifac
 
     EnterCriticalSection(&This->crit);
 
-    HeapFree(GetProcessHeap(), 0, This->action_map);
+    free( This->action_map );
     This->action_map = NULL;
     This->num_actions = 0;
 
@@ -1208,21 +1205,21 @@ ULONG WINAPI IDirectInputDevice2WImpl_Release(LPDIRECTINPUTDEVICE8W iface)
     /* Reset the FF state, free all effects, etc */
     IDirectInputDevice8_SendForceFeedbackCommand(iface, DISFFC_RESET);
 
-    HeapFree(GetProcessHeap(), 0, This->data_queue);
+    free( This->data_queue );
 
     /* Free data format */
-    HeapFree(GetProcessHeap(), 0, This->data_format.wine_df->rgodf);
-    HeapFree(GetProcessHeap(), 0, This->data_format.wine_df);
+    free( This->data_format.wine_df->rgodf );
+    free( This->data_format.wine_df );
     release_DataFormat(&This->data_format);
 
     /* Free action mapping */
-    HeapFree(GetProcessHeap(), 0, This->action_map);
+    free( This->action_map );
 
     IDirectInput_Release(&This->dinput->IDirectInput7A_iface);
     This->crit.DebugInfo->Spare[0] = 0;
     DeleteCriticalSection(&This->crit);
 
-    HeapFree(GetProcessHeap(), 0, This);
+    free( This );
 
     return ref;
 }
@@ -1405,10 +1402,9 @@ HRESULT WINAPI IDirectInputDevice2WImpl_SetProperty(
 
             This->buffersize  = pd->dwData;
             This->queue_len = min(This->buffersize, 1024);
-            HeapFree(GetProcessHeap(), 0, This->data_queue);
+            free( This->data_queue );
 
-            This->data_queue = !This->queue_len ? NULL : HeapAlloc(GetProcessHeap(), 0,
-                                This->queue_len * sizeof(DIDEVICEOBJECTDATA));
+            This->data_queue = This->queue_len ? malloc( This->queue_len * sizeof(DIDEVICEOBJECTDATA) ) : NULL;
             This->queue_head = This->queue_tail = This->overflow = 0;
 
             LeaveCriticalSection(&This->crit);
@@ -1431,8 +1427,7 @@ HRESULT WINAPI IDirectInputDevice2WImpl_SetProperty(
                     break;
                 }
             }
-            if (!found && (device_player =
-                    HeapAlloc(GetProcessHeap(), 0, sizeof(struct DevicePlayer))))
+            if (!found && (device_player = malloc( sizeof(struct DevicePlayer) )))
             {
                 list_add_tail(&This->dinput->device_players, &device_player->entry);
                 device_player->instance_guid = This->guid;
@@ -1734,10 +1729,10 @@ HRESULT direct_input_device_alloc( SIZE_T size, const IDirectInputDevice8WVtbl *
     IDirectInputDeviceImpl *This;
     DIDATAFORMAT *format;
 
-    if (!(This = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size ))) return DIERR_OUTOFMEMORY;
-    if (!(format = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*format) )))
+    if (!(This = calloc( 1, size ))) return DIERR_OUTOFMEMORY;
+    if (!(format = calloc( 1, sizeof(*format) )))
     {
-        HeapFree( GetProcessHeap(), 0, This );
+        free( This );
         return DIERR_OUTOFMEMORY;
     }
 
diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c
index a01a6adfad5..b385cc7503c 100644
--- a/dlls/dinput/dinput_main.c
+++ b/dlls/dinput/dinput_main.c
@@ -121,7 +121,7 @@ void dinput_hooks_unacquire_device(LPDIRECTINPUTDEVICE8W iface)
 
 static HRESULT create_directinput_instance(REFIID riid, LPVOID *ppDI, IDirectInputImpl **out)
 {
-    IDirectInputImpl *This = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectInputImpl) );
+    IDirectInputImpl *This = calloc( 1, sizeof(IDirectInputImpl) );
     HRESULT hr;
 
     if (!This)
@@ -136,7 +136,7 @@ static HRESULT create_directinput_instance(REFIID riid, LPVOID *ppDI, IDirectInp
     hr = IDirectInput_QueryInterface( &This->IDirectInput7A_iface, riid, ppDI );
     if (FAILED(hr))
     {
-        HeapFree( GetProcessHeap(), 0, This );
+        free( This );
         return hr;
     }
 
@@ -412,7 +412,7 @@ static ULONG WINAPI IDirectInputWImpl_Release( IDirectInput7W *iface )
     if (ref == 0)
     {
         uninitialize_directinput_instance( This );
-        HeapFree( GetProcessHeap(), 0, This );
+        free( This );
     }
 
     return ref;
@@ -547,7 +547,7 @@ static void uninitialize_directinput_instance(IDirectInputImpl *This)
 
         LIST_FOR_EACH_ENTRY_SAFE( device_player, device_player2,
                 &This->device_players, struct DevicePlayer, entry )
-            HeapFree(GetProcessHeap(), 0, device_player);
+            free( device_player );
 
         check_hook_thread();
 
@@ -833,10 +833,7 @@ static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics(
             if (enumSuccess == S_OK &&
                 should_enumerate_device(ptszUserName, dwFlags, &This->device_players, &didevi.guidInstance))
             {
-                if (device_count++)
-                    didevis = HeapReAlloc(GetProcessHeap(), 0, didevis, sizeof(DIDEVICEINSTANCEW)*device_count);
-                else
-                    didevis = HeapAlloc(GetProcessHeap(), 0, sizeof(DIDEVICEINSTANCEW)*device_count);
+                didevis = realloc( didevis, sizeof(DIDEVICEINSTANCEW) * device_count++ );
                 didevis[device_count-1] = didevi;
             }
         }
@@ -860,14 +857,14 @@ static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics(
 
         if (lpCallback(&didevis[i], lpdid, callbackFlags, --remain, pvRef) == DIENUM_STOP)
         {
-            HeapFree(GetProcessHeap(), 0, didevis);
+            free( didevis );
             IDirectInputDevice_Release(lpdid);
             return DI_OK;
         }
         IDirectInputDevice_Release(lpdid);
     }
 
-    HeapFree(GetProcessHeap(), 0, didevis);
+    free( didevis );
 
     if (dwFlags & DIEDBSFL_FORCEFEEDBACK) return DI_OK;
 
diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c
index 2280dc15040..48594e5d622 100644
--- a/dlls/dinput/joystick_hid.c
+++ b/dlls/dinput/joystick_hid.c
@@ -593,10 +593,10 @@ static ULONG hid_joystick_private_decref( struct hid_joystick *impl )
 
     if (!(ref = IDirectInputDevice2WImpl_Release( &impl->base.IDirectInputDevice8W_iface )))
     {
-        HeapFree( GetProcessHeap(), 0, tmp.usages_buf );
-        HeapFree( GetProcessHeap(), 0, tmp.output_report_buf );
-        HeapFree( GetProcessHeap(), 0, tmp.input_report_buf );
-        HeapFree( GetProcessHeap(), 0, tmp.input_extra_caps );
+        free( tmp.usages_buf );
+        free( tmp.output_report_buf );
+        free( tmp.input_report_buf );
+        free( tmp.input_extra_caps );
         HidD_FreePreparsedData( tmp.preparsed );
         CloseHandle( tmp.base.read_event );
         CloseHandle( tmp.device );
@@ -2287,18 +2287,18 @@ static HRESULT hid_joystick_create_device( IDirectInputImpl *dinput, const GUID
     preparsed = (struct hid_preparsed_data *)impl->preparsed;
 
     size = preparsed->input_caps_count * sizeof(struct extra_caps);
-    if (!(extra = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size ))) goto failed;
+    if (!(extra = calloc( 1, size ))) goto failed;
     impl->input_extra_caps = extra;
 
     size = impl->caps.InputReportByteLength;
-    if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size ))) goto failed;
+    if (!(buffer = malloc( size ))) goto failed;
     impl->input_report_buf = buffer;
     size = impl->caps.OutputReportByteLength;
-    if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size ))) goto failed;
+    if (!(buffer = malloc( size ))) goto failed;
     impl->output_report_buf = buffer;
     impl->usages_count = HidP_MaxUsageListLength( HidP_Input, 0, impl->preparsed );
     size = impl->usages_count * sizeof(USAGE_AND_PAGE);
-    if (!(usages = HeapAlloc( GetProcessHeap(), 0, size ))) goto failed;
+    if (!(usages = malloc( size ))) goto failed;
     impl->usages_buf = usages;
 
     enum_objects( impl, &filter, DIDFT_ALL, init_objects, NULL );
@@ -2350,7 +2350,7 @@ static HRESULT hid_joystick_create_device( IDirectInputImpl *dinput, const GUID
     }
 
     size = format->dwNumObjs * sizeof(*format->rgodf);
-    if (!(format->rgodf = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size ))) goto failed;
+    if (!(format->rgodf = calloc( 1, size ))) goto failed;
     format->dwSize = sizeof(*format);
     format->dwObjSize = sizeof(*format->rgodf);
     format->dwFlags = DIDF_ABSAXIS;
@@ -2419,11 +2419,11 @@ static ULONG WINAPI hid_joystick_effect_Release( IDirectInputEffect *iface )
         list_remove( &impl->entry );
         LeaveCriticalSection( &impl->joystick->base.crit );
         hid_joystick_private_decref( impl->joystick );
-        HeapFree( GetProcessHeap(), 0, impl->type_specific_buf[1] );
-        HeapFree( GetProcessHeap(), 0, impl->type_specific_buf[0] );
-        HeapFree( GetProcessHeap(), 0, impl->effect_update_buf );
-        HeapFree( GetProcessHeap(), 0, impl->effect_control_buf );
-        HeapFree( GetProcessHeap(), 0, impl );
+        free( impl->type_specific_buf[1] );
+        free( impl->type_specific_buf[0] );
+        free( impl->effect_update_buf );
+        free( impl->effect_control_buf );
+        free( impl );
     }
     return ref;
 }
@@ -3251,8 +3251,7 @@ static HRESULT hid_joystick_effect_create( struct hid_joystick *joystick, IDirec
     struct hid_joystick_effect *impl;
     ULONG report_len;
 
-    if (!(impl = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*impl) )))
-        return DIERR_OUTOFMEMORY;
+    if (!(impl = calloc( 1, sizeof(*impl) ))) return DIERR_OUTOFMEMORY;
     impl->IDirectInputEffect_iface.lpVtbl = &hid_joystick_effect_vtbl;
     impl->ref = 1;
     impl->joystick = joystick;
@@ -3263,10 +3262,10 @@ static HRESULT hid_joystick_effect_create( struct hid_joystick *joystick, IDirec
     LeaveCriticalSection( &joystick->base.crit );
 
     report_len = joystick->caps.OutputReportByteLength;
-    if (!(impl->effect_control_buf = HeapAlloc( GetProcessHeap(), 0, report_len ))) goto failed;
-    if (!(impl->effect_update_buf = HeapAlloc( GetProcessHeap(), 0, report_len ))) goto failed;
-    if (!(impl->type_specific_buf[0] = HeapAlloc( GetProcessHeap(), 0, report_len ))) goto failed;
-    if (!(impl->type_specific_buf[1] = HeapAlloc( GetProcessHeap(), 0, report_len ))) goto failed;
+    if (!(impl->effect_control_buf = malloc( report_len ))) goto failed;
+    if (!(impl->effect_update_buf = malloc( report_len ))) goto failed;
+    if (!(impl->type_specific_buf[0] = malloc( report_len ))) goto failed;
+    if (!(impl->type_specific_buf[1] = malloc( report_len ))) goto failed;
 
     impl->envelope.dwSize = sizeof(DIENVELOPE);
     impl->params.dwSize = sizeof(DIEFFECT);
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c
index fc821e2399d..f687eec5259 100644
--- a/dlls/dinput/keyboard.c
+++ b/dlls/dinput/keyboard.c
@@ -207,7 +207,7 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysKeyboar
 
     /* Create copy of default data format */
     memcpy(df, &c_dfDIKeyboard, c_dfDIKeyboard.dwSize);
-    if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed;
+    if (!(df->rgodf = malloc( df->dwNumObjs * df->dwObjSize ))) goto failed;
 
     for (i = 0; i < df->dwNumObjs; i++)
     {
@@ -227,9 +227,9 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysKeyboar
     return DI_OK;
 
 failed:
-    if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
-    HeapFree(GetProcessHeap(), 0, df);
-    HeapFree(GetProcessHeap(), 0, newDevice);
+    if (df) free( df->rgodf );
+    free( df );
+    free( newDevice );
     return DIERR_OUTOFMEMORY;
 }
 
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c
index c9301bb5146..97e2b58c6cd 100644
--- a/dlls/dinput/mouse.c
+++ b/dlls/dinput/mouse.c
@@ -161,7 +161,7 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysMouseIm
 
     /* Create copy of default data format */
     memcpy(df, &c_dfDIMouse2, c_dfDIMouse2.dwSize);
-    if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed;
+    if (!(df->rgodf = malloc( df->dwNumObjs * df->dwObjSize ))) goto failed;
     memcpy(df->rgodf, c_dfDIMouse2.rgodf, df->dwNumObjs * df->dwObjSize);
 
     /* Because we don't do any detection yet just modify instance and type */
@@ -182,9 +182,9 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysMouseIm
     return DI_OK;
 
 failed:
-    if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
-    HeapFree(GetProcessHeap(), 0, df);
-    HeapFree(GetProcessHeap(), 0, newDevice);
+    if (df) free( df->rgodf );
+    free( df );
+    free( newDevice );
     return DIERR_OUTOFMEMORY;
 }
 
-- 
2.33.0




More information about the wine-devel mailing list