Skip to content

Commit

Permalink
Fixed 4186: Enabling AC3 encoding option in audio renderer causes mem…
Browse files Browse the repository at this point in the history
…ory leaks

- ProcessAC3Frame was leaking memory when the temp buffer was not release
- NegotiateFormat was not releasing WAVEFORMATEXTENSIBLE
  • Loading branch information
tourettes authored and TwentyWasHere committed Jan 21, 2013
1 parent 28daf6b commit ded02e6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
Binary file modified DirectShowFilters/MPAudioRenderer/bin/Debug/AudioRenderer.pdb
Binary file not shown.
Binary file modified DirectShowFilters/MPAudioRenderer/bin/Debug/mpaudiorenderer.ax
Binary file not shown.
Binary file modified DirectShowFilters/MPAudioRenderer/bin/Release/mpaudiorenderer.ax
Binary file not shown.
11 changes: 11 additions & 0 deletions DirectShowFilters/MPAudioRenderer/source/AC3EncoderFilter.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ HRESULT CAC3EncoderFilter::NegotiateFormat(const WAVEFORMATEXTENSIBLE* pwfx, int
// Finally verify next sink accepts AC3 format // Finally verify next sink accepts AC3 format
WAVEFORMATEXTENSIBLE* pAC3wfx = CreateAC3Format(pwfx->Format.nSamplesPerSec, 0); WAVEFORMATEXTENSIBLE* pAC3wfx = CreateAC3Format(pwfx->Format.nSamplesPerSec, 0);


if (!pAC3wfx)
return E_OUTOFMEMORY;

hr = m_pNextSink->NegotiateFormat(pAC3wfx, nApplyChangesDepth, pChOrder); hr = m_pNextSink->NegotiateFormat(pAC3wfx, nApplyChangesDepth, pChOrder);


if (FAILED(hr)) if (FAILED(hr))
Expand All @@ -153,7 +156,10 @@ HRESULT CAC3EncoderFilter::NegotiateFormat(const WAVEFORMATEXTENSIBLE* pwfx, int
OpenAC3Encoder(m_nBitRate, m_pInputFormat->Format.nChannels, m_pInputFormat->Format.nSamplesPerSec); OpenAC3Encoder(m_nBitRate, m_pInputFormat->Format.nChannels, m_pInputFormat->Format.nSamplesPerSec);
} }
else else
{
SAFE_DELETE_WAVEFORMATEX(pAC3wfx);
LogWaveFormat(pwfx, "AC3 - "); LogWaveFormat(pwfx, "AC3 - ");
}


*pChOrder = AC3_ORDER; *pChOrder = AC3_ORDER;


Expand Down Expand Up @@ -514,12 +520,17 @@ HRESULT CAC3EncoderFilter::ProcessAC3Frame(const BYTE* pData)
ASSERT(pOutData); ASSERT(pOutData);
BYTE* buf = (BYTE*)malloc(m_nMaxCompressedAC3FrameSize); // temporary buffer BYTE* buf = (BYTE*)malloc(m_nMaxCompressedAC3FrameSize); // temporary buffer


if (!buf)
return E_OUTOFMEMORY;

int AC3length = ac3_encoder_frame(m_pEncoder, (short*)pData, buf, m_nMaxCompressedAC3FrameSize); int AC3length = ac3_encoder_frame(m_pEncoder, (short*)pData, buf, m_nMaxCompressedAC3FrameSize);
nOffset += CreateAC3Bitstream(buf, AC3length, pOutData + nOffset); nOffset += CreateAC3Bitstream(buf, AC3length, pOutData + nOffset);
m_pNextOutSample->SetActualDataLength(nOffset); m_pNextOutSample->SetActualDataLength(nOffset);
if (nOffset >= nSize) if (nOffset >= nSize)
OutputNextSample(); OutputNextSample();


free(buf);

return S_OK; return S_OK;
} }


2 changes: 1 addition & 1 deletion DirectShowFilters/MPAudioRenderer/source/Settings.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ AudioRendererSettings::AudioRendererSettings() :
m_bExpandMonoToStereo(true) m_bExpandMonoToStereo(true)
{ {
LogRotate(); LogRotate();
Log("MP Audio Renderer - v1.0.4"); Log("MP Audio Renderer - v1.0.5");


LoadSettingsFromRegistry(); LoadSettingsFromRegistry();
} }
Expand Down

0 comments on commit ded02e6

Please sign in to comment.