hidclass.sys: Use msvcrt allocation functions.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2021-06-04 11:30:31 +02:00 committed by Alexandre Julliard
parent 0a07652420
commit 1c5e57fc75
4 changed files with 40 additions and 37 deletions

View File

@ -18,6 +18,7 @@
*/
#include <stdarg.h>
#include <stdlib.h>
#define NONAMELESSUNION
#include "hid.h"
@ -50,26 +51,26 @@ struct ReportRingBuffer* RingBuffer_Create(UINT buffer_size)
TRACE("Create Ring Buffer with buffer size %i\n",buffer_size);
ring = HeapAlloc(GetProcessHeap(), 0, sizeof(*ring));
ring = malloc(sizeof(*ring));
if (!ring)
return NULL;
ring->start = ring->end = 0;
ring->size = BASE_BUFFER_SIZE;
ring->buffer_size = buffer_size;
ring->pointer_alloc = 2;
ring->pointers = HeapAlloc(GetProcessHeap(), 0, sizeof(UINT) * ring->pointer_alloc);
ring->pointers = malloc(sizeof(UINT) * ring->pointer_alloc);
if (!ring->pointers)
{
HeapFree(GetProcessHeap(), 0, ring);
free(ring);
return NULL;
}
for (i = 0; i < ring->pointer_alloc; i++)
ring->pointers[i] = POINTER_UNUSED;
ring->buffer = HeapAlloc(GetProcessHeap(), 0, buffer_size * ring->size);
ring->buffer = malloc(buffer_size * ring->size);
if (!ring->buffer)
{
HeapFree(GetProcessHeap(), 0, ring->pointers);
HeapFree(GetProcessHeap(), 0, ring);
free(ring->pointers);
free(ring);
return NULL;
}
InitializeCriticalSection(&ring->lock);
@ -79,11 +80,11 @@ struct ReportRingBuffer* RingBuffer_Create(UINT buffer_size)
void RingBuffer_Destroy(struct ReportRingBuffer *ring)
{
HeapFree(GetProcessHeap(), 0, ring->buffer);
HeapFree(GetProcessHeap(), 0, ring->pointers);
free(ring->buffer);
free(ring->pointers);
ring->lock.DebugInfo->Spare[0] = 0;
DeleteCriticalSection(&ring->lock);
HeapFree(GetProcessHeap(), 0, ring);
free(ring);
}
UINT RingBuffer_GetBufferSize(struct ReportRingBuffer *ring)
@ -113,13 +114,13 @@ NTSTATUS RingBuffer_SetSize(struct ReportRingBuffer *ring, UINT size)
if (ring->pointers[i] != POINTER_UNUSED)
ring->pointers[i] = 0;
}
new_buffer = HeapAlloc(GetProcessHeap(), 0, ring->buffer_size * size);
new_buffer = malloc(ring->buffer_size * size);
if (!new_buffer)
{
LeaveCriticalSection(&ring->lock);
return STATUS_NO_MEMORY;
}
HeapFree(GetProcessHeap(), 0, ring->buffer);
free(ring->buffer);
ring->buffer = new_buffer;
ring->size = size;
LeaveCriticalSection(&ring->lock);

View File

@ -507,7 +507,7 @@ static int parse_descriptor(BYTE *descriptor, unsigned int index, unsigned int l
case TAG_MAIN_FEATURE:
for (j = 0; j < caps->ReportCount; j++)
{
feature = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*feature));
feature = calloc(1, sizeof(*feature));
list_add_tail(&collection->features, &feature->entry);
if (bTag == TAG_MAIN_INPUT)
feature->type = HidP_Input;
@ -532,7 +532,7 @@ static int parse_descriptor(BYTE *descriptor, unsigned int index, unsigned int l
break;
case TAG_MAIN_COLLECTION:
{
struct collection *subcollection = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct collection));
struct collection *subcollection = calloc(1, sizeof(struct collection));
list_add_tail(&collection->collections, &subcollection->entry);
subcollection->parent = collection;
/* Only set our collection once...
@ -598,7 +598,7 @@ static int parse_descriptor(BYTE *descriptor, unsigned int index, unsigned int l
break;
case TAG_GLOBAL_PUSH:
{
struct caps_stack *saved = HeapAlloc(GetProcessHeap(), 0, sizeof(*saved));
struct caps_stack *saved = malloc(sizeof(*saved));
saved->caps = *caps;
TRACE("Push\n");
list_add_tail(stack, &saved->entry);
@ -615,7 +615,7 @@ static int parse_descriptor(BYTE *descriptor, unsigned int index, unsigned int l
saved = LIST_ENTRY(tail, struct caps_stack, entry);
*caps = saved->caps;
list_remove(tail);
HeapFree(GetProcessHeap(), 0, saved);
free(saved);
}
else
ERR("Pop but no stack!\n");
@ -928,7 +928,7 @@ static WINE_HIDP_PREPARSED_DATA* build_PreparseData(struct collection *base_coll
nodes_offset = size;
size += node_count * sizeof(WINE_HID_LINK_COLLECTION_NODE);
data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
data = calloc(1, size);
data->magic = HID_MAGIC;
data->dwSize = size;
data->caps.Usage = base_collection->caps.u.NotRange.Usage;
@ -953,9 +953,9 @@ static void free_collection(struct collection *collection)
LIST_FOR_EACH_ENTRY_SAFE(fentry, fnext, &collection->features, struct feature, entry)
{
list_remove(&fentry->entry);
HeapFree(GetProcessHeap(), 0, fentry);
free(fentry);
}
HeapFree(GetProcessHeap(), 0, collection);
free(collection);
}
WINE_HIDP_PREPARSED_DATA* ParseDescriptor(BYTE *descriptor, unsigned int length)
@ -983,7 +983,7 @@ WINE_HIDP_PREPARSED_DATA* ParseDescriptor(BYTE *descriptor, unsigned int length)
list_init(&caps_stack);
base = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*base));
base = calloc(1, sizeof(*base));
base->index = 1;
list_init(&base->features);
list_init(&base->collections);
@ -1001,7 +1001,7 @@ WINE_HIDP_PREPARSED_DATA* ParseDescriptor(BYTE *descriptor, unsigned int length)
LIST_FOR_EACH_ENTRY_SAFE(entry, cursor, &caps_stack, struct caps_stack, entry)
{
list_remove(&entry->entry);
HeapFree(GetProcessHeap(), 0, entry);
free(entry);
}
}

View File

@ -19,6 +19,7 @@
*/
#include <stdarg.h>
#include <stdlib.h>
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include "hid.h"
@ -115,7 +116,7 @@ static void hid_device_send_input(DEVICE_OBJECT *device, HID_XFER_PACKET *packet
data_size = offsetof(RAWINPUT, data.hid.bRawData) + packet->reportBufferLen;
if (!(id = ext->u.pdo.preparsed_data->reports[0].reportID)) data_size += 1;
if (!(rawinput = HeapAlloc(GetProcessHeap(), 0, data_size)))
if (!(rawinput = malloc(data_size)))
{
ERR("Failed to allocate rawinput data!\n");
return;
@ -138,7 +139,7 @@ static void hid_device_send_input(DEVICE_OBJECT *device, HID_XFER_PACKET *packet
input.u.hi.wParamL = 0;
__wine_send_input(0, &input, rawinput);
HeapFree(GetProcessHeap(), 0, rawinput);
free(rawinput);
}
static void HID_Device_processQueue(DEVICE_OBJECT *device)
@ -148,7 +149,7 @@ static void HID_Device_processQueue(DEVICE_OBJECT *device)
UINT buffer_size = RingBuffer_GetBufferSize(ext->u.pdo.ring_buffer);
HID_XFER_PACKET *packet;
packet = HeapAlloc(GetProcessHeap(), 0, buffer_size);
packet = malloc(buffer_size);
while((irp = pop_irp_from_queue(ext)))
{
@ -174,7 +175,7 @@ static void HID_Device_processQueue(DEVICE_OBJECT *device)
}
IoCompleteRequest( irp, IO_NO_INCREMENT );
}
HeapFree(GetProcessHeap(), 0, packet);
free(packet);
}
static DWORD CALLBACK hid_device_thread(void *args)
@ -189,7 +190,7 @@ static DWORD CALLBACK hid_device_thread(void *args)
BASE_DEVICE_EXTENSION *ext = device->DeviceExtension;
USHORT report_size = ext->u.pdo.preparsed_data->caps.InputReportByteLength;
packet = HeapAlloc(GetProcessHeap(), 0, sizeof(*packet) + report_size);
packet = malloc(sizeof(*packet) + report_size);
packet->reportBuffer = (BYTE *)packet + sizeof(*packet);
if (ext->u.pdo.information.Polled)
@ -347,7 +348,7 @@ static NTSTATUS HID_get_feature(BASE_DEVICE_EXTENSION *ext, IRP *irp)
TRACE_(hid_report)("Device %p Buffer length %i Buffer %p\n", ext, irpsp->Parameters.DeviceIoControl.OutputBufferLength, out_buffer);
len = sizeof(*packet) + irpsp->Parameters.DeviceIoControl.OutputBufferLength;
packet = HeapAlloc(GetProcessHeap(), 0, len);
packet = malloc(len);
packet->reportBufferLen = irpsp->Parameters.DeviceIoControl.OutputBufferLength;
packet->reportBuffer = ((BYTE*)packet) + sizeof(*packet);
packet->reportId = out_buffer[0];
@ -367,7 +368,7 @@ static NTSTATUS HID_get_feature(BASE_DEVICE_EXTENSION *ext, IRP *irp)
TRACE_(hid_report)("Result 0x%x get %li bytes\n", rc, irp->IoStatus.Information);
HeapFree(GetProcessHeap(), 0, packet);
free(packet);
return rc;
}
@ -496,7 +497,7 @@ NTSTATUS WINAPI pdo_ioctl(DEVICE_OBJECT *device, IRP *irp)
BYTE *buffer = MmGetSystemAddressForMdlSafe(irp->MdlAddress, NormalPagePriority);
ULONG out_length;
packet = HeapAlloc(GetProcessHeap(), 0, packet_size);
packet = malloc(packet_size);
if (ext->u.pdo.preparsed_data->reports[0].reportID)
packet->reportId = buffer[0];
@ -514,7 +515,7 @@ NTSTATUS WINAPI pdo_ioctl(DEVICE_OBJECT *device, IRP *irp)
else
irp->IoStatus.Information = 0;
irp->IoStatus.u.Status = rc;
HeapFree(GetProcessHeap(), 0, packet);
free(packet);
break;
}
case IOCTL_SET_NUM_DEVICE_INPUT_BUFFERS:
@ -578,7 +579,7 @@ NTSTATUS WINAPI pdo_read(DEVICE_OBJECT *device, IRP *irp)
IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation(irp);
int ptr = -1;
packet = HeapAlloc(GetProcessHeap(), 0, buffer_size);
packet = malloc(buffer_size);
ptr = PtrToUlong( irp->Tail.Overlay.OriginalFileObject->FsContext );
irp->IoStatus.Information = 0;
@ -639,7 +640,7 @@ NTSTATUS WINAPI pdo_read(DEVICE_OBJECT *device, IRP *irp)
IoCompleteRequest(irp, IO_NO_INCREMENT);
}
}
HeapFree(GetProcessHeap(), 0, packet);
free(packet);
return rc;
}

View File

@ -21,6 +21,7 @@
#define NONAMELESSUNION
#include <unistd.h>
#include <stdarg.h>
#include <stdlib.h>
#include "initguid.h"
#include "hid.h"
#include "devguid.h"
@ -239,19 +240,19 @@ static void create_child(minidriver *minidriver, DEVICE_OBJECT *fdo)
return;
}
reportDescriptor = HeapAlloc(GetProcessHeap(), 0, descriptor.DescriptorList[i].wReportLength);
reportDescriptor = malloc(descriptor.DescriptorList[i].wReportLength);
status = call_minidriver(IOCTL_HID_GET_REPORT_DESCRIPTOR, fdo, NULL, 0,
reportDescriptor, descriptor.DescriptorList[i].wReportLength);
if (status != STATUS_SUCCESS)
{
ERR("Cannot get Report Descriptor(%x)\n",status);
HeapFree(GetProcessHeap(), 0, reportDescriptor);
free(reportDescriptor);
IoDeleteDevice(child_pdo);
return;
}
pdo_ext->u.pdo.preparsed_data = ParseDescriptor(reportDescriptor, descriptor.DescriptorList[i].wReportLength);
HeapFree(GetProcessHeap(), 0, reportDescriptor);
free(reportDescriptor);
if (!pdo_ext->u.pdo.preparsed_data)
{
ERR("Cannot parse Report Descriptor\n");
@ -475,7 +476,7 @@ static NTSTATUS pdo_pnp(DEVICE_OBJECT *device, IRP *irp)
}
CloseHandle(ext->u.pdo.halt_event);
HeapFree(GetProcessHeap(), 0, ext->u.pdo.preparsed_data);
free(ext->u.pdo.preparsed_data);
if (ext->u.pdo.ring_buffer)
RingBuffer_Destroy(ext->u.pdo.ring_buffer);
@ -561,7 +562,7 @@ static void WINAPI driver_unload(DRIVER_OBJECT *driver)
if (md->DriverUnload)
md->DriverUnload(md->minidriver.DriverObject);
list_remove(&md->entry);
HeapFree(GetProcessHeap(), 0, md);
free(md);
}
}
@ -569,7 +570,7 @@ NTSTATUS WINAPI HidRegisterMinidriver(HID_MINIDRIVER_REGISTRATION *registration)
{
minidriver *driver;
if (!(driver = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*driver))))
if (!(driver = calloc(1, sizeof(*driver))))
return STATUS_NO_MEMORY;
driver->DriverUnload = registration->DriverObject->DriverUnload;