From 47c658815bacef9f9663f06e8903f0a48d7c122f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 31 Mar 2025 16:38:58 +0800 Subject: [PATCH] Sound: fix typo and mem leaks --- src/detection/sound/sound_obsd.c | 2 +- src/detection/sound/sound_windows.cpp | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/detection/sound/sound_obsd.c b/src/detection/sound/sound_obsd.c index 2b19d0eb5..5b83f9578 100644 --- a/src/detection/sound/sound_obsd.c +++ b/src/detection/sound/sound_obsd.c @@ -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); diff --git a/src/detection/sound/sound_windows.cpp b/src/detection/sound/sound_windows.cpp index fece395f0..4845cac5f 100644 --- a/src/detection/sound/sound_windows.cpp +++ b/src/detection/sound/sound_windows.cpp @@ -9,6 +9,14 @@ extern "C" { #include #include +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;