diff --git a/dlls/winecoreaudio.drv/mmdevdrv.c b/dlls/winecoreaudio.drv/mmdevdrv.c index 642610b4b60..56f533f8bc1 100644 --- a/dlls/winecoreaudio.drv/mmdevdrv.c +++ b/dlls/winecoreaudio.drv/mmdevdrv.c @@ -580,12 +580,6 @@ HRESULT WINAPI AUDDRV_GetAudioEndpoint(GUID *guid, IMMDevice *dev, IAudioClient This->adevid = adevid; - if(!(This->stream->unit = get_audiounit(This->dataflow, This->adevid))){ - HeapFree(GetProcessHeap(), 0, This->stream); - HeapFree(GetProcessHeap(), 0, This); - return AUDCLNT_E_DEVICE_INVALIDATED; - } - *out = (IAudioClient *)&This->IAudioClient3_iface; IAudioClient3_AddRef(&This->IAudioClient3_iface); @@ -1262,6 +1256,14 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface, if(mode == AUDCLNT_SHAREMODE_EXCLUSIVE) This->stream->bufsize_frames -= This->stream->bufsize_frames % This->stream->period_frames; + if(!(This->stream->unit = get_audiounit(This->dataflow, This->adevid))){ + CoTaskMemFree(This->stream->fmt); + This->stream->fmt = NULL; + OSSpinLockUnlock(&This->stream->lock); + LeaveCriticalSection(&g_sessions_lock); + return AUDCLNT_E_DEVICE_INVALIDATED; + } + hr = ca_setup_audiounit(This->dataflow, This->stream->unit, This->stream->fmt, &This->stream->dev_desc, &This->stream->converter); if(FAILED(hr)){ CoTaskMemFree(This->stream->fmt);