user32: Remove unnecessary device path memory allocation.

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-04-16 13:48:09 +02:00 committed by Alexandre Julliard
parent 4bdf8f928a
commit b3111f3a32
1 changed files with 9 additions and 18 deletions

View File

@ -44,7 +44,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(rawinput);
struct device struct device
{ {
WCHAR *path; SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail;
HANDLE file; HANDLE file;
RID_DEVICE_INFO info; RID_DEVICE_INFO info;
PHIDP_PREPARSED_DATA data; PHIDP_PREPARSED_DATA data;
@ -94,7 +94,6 @@ static struct device *add_device(HDEVINFO set, SP_DEVICE_INTERFACE_DATA *iface)
SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail; SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail;
struct device *device; struct device *device;
HANDLE file; HANDLE file;
WCHAR *path;
DWORD size; DWORD size;
SetupDiGetDeviceInterfaceDetailW(set, iface, NULL, 0, &size, NULL); SetupDiGetDeviceInterfaceDetailW(set, iface, NULL, 0, &size, NULL);
@ -113,20 +112,12 @@ static struct device *add_device(HDEVINFO set, SP_DEVICE_INTERFACE_DATA *iface)
TRACE("Found HID device %s.\n", debugstr_w(detail->DevicePath)); TRACE("Found HID device %s.\n", debugstr_w(detail->DevicePath));
if (!(path = heap_strdupW(detail->DevicePath))) file = CreateFileW(detail->DevicePath, GENERIC_READ | GENERIC_WRITE,
{
ERR("Failed to allocate memory.\n");
heap_free(detail);
return NULL;
}
heap_free(detail);
file = CreateFileW(path, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0); FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
if (file == INVALID_HANDLE_VALUE) if (file == INVALID_HANDLE_VALUE)
{ {
ERR("Failed to open device file %s, error %u.\n", debugstr_w(path), GetLastError()); ERR("Failed to open device file %s, error %u.\n", debugstr_w(detail->DevicePath), GetLastError());
heap_free(path); heap_free(detail);
return NULL; return NULL;
} }
@ -135,12 +126,12 @@ static struct device *add_device(HDEVINFO set, SP_DEVICE_INTERFACE_DATA *iface)
{ {
ERR("Failed to allocate memory.\n"); ERR("Failed to allocate memory.\n");
CloseHandle(file); CloseHandle(file);
heap_free(path); heap_free(detail);
return NULL; return NULL;
} }
device = &rawinput_devices[rawinput_devices_count++]; device = &rawinput_devices[rawinput_devices_count++];
device->path = path; device->detail = detail;
device->file = file; device->file = file;
device->info.cbSize = sizeof(RID_DEVICE_INFO); device->info.cbSize = sizeof(RID_DEVICE_INFO);
@ -171,7 +162,7 @@ static void find_devices(void)
for (idx = 0; idx < rawinput_devices_count; ++idx) for (idx = 0; idx < rawinput_devices_count; ++idx)
{ {
CloseHandle(rawinput_devices[idx].file); CloseHandle(rawinput_devices[idx].file);
heap_free(rawinput_devices[idx].path); heap_free(rawinput_devices[idx].detail);
} }
rawinput_devices_count = 0; rawinput_devices_count = 0;
@ -681,8 +672,8 @@ UINT WINAPI GetRawInputDeviceInfoW(HANDLE handle, UINT command, void *data, UINT
} }
else else
{ {
*data_size = lstrlenW(device->path) + 1; *data_size = lstrlenW(device->detail->DevicePath) + 1;
to_copy = device->path; to_copy = device->detail->DevicePath;
} }
to_copy_bytes = *data_size * sizeof(WCHAR); to_copy_bytes = *data_size * sizeof(WCHAR);
break; break;