summaryrefslogtreecommitdiffstats
path: root/media/audio
diff options
context:
space:
mode:
authordalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-23 00:54:59 +0000
committerdalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-23 00:54:59 +0000
commita3c4f9da509e02874b46afaadf8140bc20b9e4f6 (patch)
tree8196a9707df6b229e2a8df73cfe625cee44ac1b7 /media/audio
parentc4f5c6ad659e7f221371d32584fbb54e9276ac68 (diff)
downloadchromium_src-a3c4f9da509e02874b46afaadf8140bc20b9e4f6.zip
chromium_src-a3c4f9da509e02874b46afaadf8140bc20b9e4f6.tar.gz
chromium_src-a3c4f9da509e02874b46afaadf8140bc20b9e4f6.tar.bz2
Fix buffer leak in Wave In/Out implementation.
|waveout_| and |wavein_| are NULL when we call FreeBuffers() in their respective implementations, which means the unprepareheader calls never succeed. BUG=145725 TEST=none Review URL: https://chromiumcodereview.appspot.com/12330063 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@184238 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio')
-rw-r--r--media/audio/win/wavein_input_win.cc5
-rw-r--r--media/audio/win/waveout_output_win.cc22
2 files changed, 15 insertions, 12 deletions
diff --git a/media/audio/win/wavein_input_win.cc b/media/audio/win/wavein_input_win.cc
index aa0b659..924768c 100644
--- a/media/audio/win/wavein_input_win.cc
+++ b/media/audio/win/wavein_input_win.cc
@@ -183,7 +183,9 @@ void PCMWaveInAudioInputStream::Close() {
Stop();
if (wavein_) {
- // waveInClose() generates a WIM_CLOSE callback. In case start was never
+ FreeBuffers();
+
+ // waveInClose() generates a WIM_CLOSE callback. In case Start() was never
// called, force a reset to ensure close succeeds.
MMRESULT res = ::waveInReset(wavein_);
DCHECK_EQ(res, static_cast<MMRESULT>(MMSYSERR_NOERROR));
@@ -191,7 +193,6 @@ void PCMWaveInAudioInputStream::Close() {
DCHECK_EQ(res, static_cast<MMRESULT>(MMSYSERR_NOERROR));
state_ = kStateClosed;
wavein_ = NULL;
- FreeBuffers();
}
// Tell the audio manager that we have been released. This can result in
diff --git a/media/audio/win/waveout_output_win.cc b/media/audio/win/waveout_output_win.cc
index 6fa2a30..5e7b29a 100644
--- a/media/audio/win/waveout_output_win.cc
+++ b/media/audio/win/waveout_output_win.cc
@@ -298,20 +298,22 @@ void PCMWaveOutAudioOutputStream::Stop() {
// as callback_ is set to NULL. Just print it and hope somebody somehow
// will find it...
void PCMWaveOutAudioOutputStream::Close() {
- Stop(); // Just to be sure. No-op if not playing.
+ // Force Stop() to ensure it's safe to release buffers and free the stream.
+ Stop();
+
if (waveout_) {
- MMRESULT result = ::waveOutClose(waveout_);
- // If ::waveOutClose() fails we cannot just delete the stream, callback
- // may try to access it and would crash. Better to leak the stream.
- if (result != MMSYSERR_NOERROR) {
- HandleError(result);
- state_ = PCMA_PLAYING;
- return;
- }
+ FreeBuffers();
+
+ // waveOutClose() generates a WIM_CLOSE callback. In case Start() was never
+ // called, force a reset to ensure close succeeds.
+ MMRESULT res = ::waveOutReset(waveout_);
+ DCHECK_EQ(res, static_cast<MMRESULT>(MMSYSERR_NOERROR));
+ res = ::waveOutClose(waveout_);
+ DCHECK_EQ(res, static_cast<MMRESULT>(MMSYSERR_NOERROR));
state_ = PCMA_CLOSED;
waveout_ = NULL;
- FreeBuffers();
}
+
// Tell the audio manager that we have been released. This can result in
// the manager destroying us in-place so this needs to be the last thing
// we do on this function.