From fca6278784e2d1923ebb8f4f635a8bcd0aade00c Mon Sep 17 00:00:00 2001 From: Stefan Hacker Date: Sun, 15 Mar 2015 21:54:21 +0100 Subject: [PATCH] Fix double free in WASAPI no positional audio fallback code-path Also explicitly NULL pointers handed to getAndCheckMixFormat for clarity. --- src/mumble/WASAPI.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/mumble/WASAPI.cpp b/src/mumble/WASAPI.cpp index 10ee52c8e..40e3730ee 100644 --- a/src/mumble/WASAPI.cpp +++ b/src/mumble/WASAPI.cpp @@ -133,6 +133,9 @@ bool getAndCheckMixFormat(const char* sourceName, WAVEFORMATEXTENSIBLE **waveFormatExtensible, SAMPLEFORMAT *sampleFormat) { + *waveFormatEx = NULL; + *waveFormatExtensible = NULL; + HRESULT hr = audioClient->GetMixFormat(waveFormatEx); if (FAILED(hr)) { qWarning("%s: %s GetMixFormat failed: hr=0x%08lx", sourceName, deviceName, hr); @@ -161,7 +164,7 @@ bool getAndCheckMixFormat(const char* sourceName, } if (*sampleFormat == SAMPLEFORMAT::SampleFloat) { - if ((*waveFormatEx)->wBitsPerSample != (sizeof(float) * 8)) { + if ((*waveFormatEx)->wBitsPerSample != (sizeof(float) * 8)) { qWarning() << sourceName << ":" << deviceName << "unexpected number of bits per sample for IEEE Float:" << (*waveFormatEx)->wBitsPerSample; return false; } @@ -954,12 +957,12 @@ void WASAPIOutput::run() { if (hr == S_FALSE) { qWarning("WASAPIOutput: Driver says no to 2 channel output. Closest format: %d channels @ %d kHz", closestFormat->nChannels, closestFormat->nSamplesPerSec); CoTaskMemFree(pwfx); - CoTaskMemFree(closestFormat); // Fall back to whatever the device offers. if (!getAndCheckMixFormat("WASAPIOutput", "Output", pAudioClient, &pwfx, &pwfxe, &eSampleFormat)) { + CoTaskMemFree(closestFormat); goto cleanup; } } else if (FAILED(hr)) {