aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2012-02-16 10:08:50 -0800
committerChris Robinson <[email protected]>2012-02-16 10:08:50 -0800
commitdeee6a73f021b6c08864ce7c9cb4e5e9d1f40beb (patch)
tree884fc8b1676e75c0c7b1571a1a3c061820ddbd21
parent84ba0a94c0a812cb07edec9e964c161f4d55b8b1 (diff)
Fix a device count leak and make sure COM is cleaned up if an mmdevice open fails
-rw-r--r--Alc/backends/mmdevapi.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/Alc/backends/mmdevapi.c b/Alc/backends/mmdevapi.c
index 0c2e00b0..e109b5b5 100644
--- a/Alc/backends/mmdevapi.c
+++ b/Alc/backends/mmdevapi.c
@@ -452,16 +452,16 @@ static DWORD CALLBACK MMDevApiMsgProc(void *ptr)
ALuint deviceCount = 0;
MMDevApiData *data;
ALCdevice *device;
- HRESULT hr;
+ HRESULT hr, cohr;
MSG msg;
TRACE("Starting message thread\n");
- hr = CoInitialize(NULL);
- if(FAILED(hr))
+ cohr = CoInitialize(NULL);
+ if(FAILED(cohr))
{
- WARN("Failed to initialize COM: 0x%08lx\n", hr);
- req->result = hr;
+ WARN("Failed to initialize COM: 0x%08lx\n", cohr);
+ req->result = cohr;
SetEvent(req->FinishedEvt);
return 0;
}
@@ -495,10 +495,11 @@ static DWORD CALLBACK MMDevApiMsgProc(void *ptr)
device = (ALCdevice*)msg.lParam;
data = device->ExtraData;
- hr = S_OK;
+ cohr = S_OK;
+ hr = E_FAIL;
if(++deviceCount == 1)
- hr = CoInitialize(NULL);
- if(SUCCEEDED(hr))
+ cohr = CoInitialize(NULL);
+ if(SUCCEEDED(cohr))
hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, &ptr);
if(SUCCEEDED(hr))
{
@@ -517,6 +518,8 @@ static DWORD CALLBACK MMDevApiMsgProc(void *ptr)
if(data->mmdev)
IMMDevice_Release(data->mmdev);
data->mmdev = NULL;
+ if(--deviceCount == 0 && SUCCEEDED(cohr))
+ CoUninitialize();
}
req->result = hr;