Sound: fix typo and mem leaks

This commit is contained in:
李通洲
2025-03-31 16:38:58 +08:00
parent b0d0c74073
commit 47c658815b
2 changed files with 11 additions and 3 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ const char* ffDetectSound(FFlist* devices)
return "sioctl_ondesc() failed";
if (bundle.iLevel != bundle.iMute || bundle.iLevel == 0)
return "Unexpecd sioctl_ondesc() result";
return "Unexpected sioctl_ondesc() result";
FFSoundDevice* device = ffListAdd(devices);
ffStrbufInitS(&device->name, bundle.name);
+10 -2
View File
@@ -9,6 +9,14 @@ extern "C" {
#include <endpointvolume.h>
#include <functiondiscoverykeys_devpkey.h>
static void ffCoTaskMemFreeWrapper(void* pptr)
{
assert(pptr != NULL);
void* ptr = *(void**)pptr;
if (ptr) CoTaskMemFree(ptr);
}
#define FF_COTASK_AUTO_FREE __attribute__((__cleanup__(ffCoTaskMemFreeWrapper)))
const char* ffDetectSound(FFlist* devices /* List of FFSoundDevice */)
{
const char* error = ffInitCom();
@@ -20,7 +28,7 @@ const char* ffDetectSound(FFlist* devices /* List of FFSoundDevice */)
if (FAILED(CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void **)&pEnum)))
return "CoCreateInstance(CLSID_MMDeviceEnumerator) failed";
LPWSTR mainDeviceId = NULL;
LPWSTR FF_COTASK_AUTO_FREE mainDeviceId = NULL;
{
IMMDevice* FF_AUTO_RELEASE_COM_OBJECT pDefaultDevice = NULL;
@@ -47,7 +55,7 @@ const char* ffDetectSound(FFlist* devices /* List of FFSoundDevice */)
if (FAILED(pDevices->Item(deviceIdx, &immDevice)))
continue;
LPWSTR immDeviceId = NULL;
LPWSTR FF_COTASK_AUTO_FREE immDeviceId = NULL;
if (FAILED(immDevice->GetId(&immDeviceId)))
continue;