Jinoh Kang (@iamahuman) commented about dlls/windows.media.speech/recognizer.c:
- if (FAILED(hr = IAudioClient_Initialize(session->audio_client, AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_EVENTCALLBACK, buffer_duration, 0, &wfx, NULL)))
goto cleanup;
- if (FAILED(hr = IAudioClient_SetEventHandle(session->audio_client, session->audio_buf_event)))
goto cleanup;
- hr = IAudioClient_GetService(session->audio_client, &IID_IAudioCaptureClient, (void **)&session->capture_client);
- session->capture_wfx = wfx;
+cleanup:
- if (FAILED(hr))
- {
if (session->audio_client) IAudioClient_Release(session->audio_client);
if (session->audio_buf_event) CloseHandle(session->audio_buf_event);
I think it's better to consolidate all resource cleanup to the `error:` label inside `recognizer_factory_Create`. Alternatively, we should set it to `NULL` after closing the handle (or releasing the interface). In general, we don't want to leave an object in an inconsistent state if it's not our own (e.g. it's passed by pointer as a parameter).