1
0
mirror of https://github.com/wine-mirror/wine synced 2024-07-03 08:19:41 +00:00

mmdevapi: Move name string duplication in MMDevice_Create() from caller.

This commit is contained in:
Davide Beatrici 2023-08-30 00:43:30 +02:00 committed by Alexandre Julliard
parent b1b231f370
commit cdfb85220f

View File

@ -312,7 +312,7 @@ static const WCHAR *find_product_name_override(const WCHAR *device_id)
* If GUID is null, a random guid will be assigned
* and the device will be created
*/
static MMDevice *MMDevice_Create(WCHAR *name, GUID *id, EDataFlow flow, DWORD state, BOOL setdefault)
static MMDevice *MMDevice_Create(const WCHAR *name, GUID *id, EDataFlow flow, DWORD state, BOOL setdefault)
{
HKEY key, root;
MMDevice *device, *cur = NULL;
@ -351,7 +351,7 @@ static MMDevice *MMDevice_Create(WCHAR *name, GUID *id, EDataFlow flow, DWORD st
WARN("Modifying an MMDevice with postitive reference count!\n");
free(cur->drv_id);
cur->drv_id = name;
cur->drv_id = wcsdup(name);
cur->flow = flow;
cur->state = state;
@ -373,7 +373,7 @@ static MMDevice *MMDevice_Create(WCHAR *name, GUID *id, EDataFlow flow, DWORD st
PROPVARIANT pv;
pv.vt = VT_LPWSTR;
pv.pwszVal = name;
pv.pwszVal = cur->drv_id;
if (SUCCEEDED(set_driver_prop_value(id, flow, &devicepath_key))) {
PROPVARIANT pv2;
@ -482,10 +482,7 @@ HRESULT load_devices_from_reg(void)
&& SUCCEEDED(MMDevice_GetPropValue(&guid, curflow, (const PROPERTYKEY*)&DEVPKEY_Device_FriendlyName, &pv))
&& pv.vt == VT_LPWSTR)
{
DWORD size_bytes = (lstrlenW(pv.pwszVal) + 1) * sizeof(WCHAR);
WCHAR *name = malloc(size_bytes);
memcpy(name, pv.pwszVal, size_bytes);
MMDevice_Create(name, &guid, curflow,
MMDevice_Create(pv.pwszVal, &guid, curflow,
DEVICE_STATE_NOTPRESENT, FALSE);
CoTaskMemFree(pv.pwszVal);
}
@ -544,21 +541,13 @@ HRESULT load_driver_devices(EDataFlow flow)
for (i = 0; i < params.num; i++) {
GUID guid;
WCHAR *id;
MMDevice *dev;
const WCHAR *name = (WCHAR *)((char *)params.endpoints + params.endpoints[i].name);
const char *dev_name = (char *)params.endpoints + params.endpoints[i].device;
const unsigned int size = (wcslen(name) + 1) * sizeof(WCHAR);
if (!(id = malloc(size))) {
params.result = E_OUTOFMEMORY;
goto end;
}
memcpy(id, name, size);
drvs.pget_device_guid(flow, dev_name, &guid);
dev = MMDevice_Create(id, &guid, flow, DEVICE_STATE_ACTIVE, params.default_idx == i);
dev = MMDevice_Create(name, &guid, flow, DEVICE_STATE_ACTIVE, params.default_idx == i);
set_format(dev);
}