Commit cdfb8522 authored by Davide Beatrici's avatar Davide Beatrici Committed by Alexandre Julliard

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

parent b1b231f3
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment