From cdfb85220ffa6e1bd2b701306492380ef3c74fd7 Mon Sep 17 00:00:00 2001 From: Davide Beatrici Date: Wed, 30 Aug 2023 00:43:30 +0200 Subject: [PATCH] mmdevapi: Move name string duplication in MMDevice_Create() from caller. --- dlls/mmdevapi/devenum.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/dlls/mmdevapi/devenum.c b/dlls/mmdevapi/devenum.c index f93bfa83ec7..10037a7affe 100644 --- a/dlls/mmdevapi/devenum.c +++ b/dlls/mmdevapi/devenum.c @@ -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); }