From 870dc73f78c9613a7b3000616f9f99afc0df1602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Fri, 12 Sep 2008 17:24:32 +0000 Subject: [PATCH] Fixed CID 1292. If the allocation or adding to the list of the very first Buffer failed, the buffer data would be leaked. Note that for failure to allocate later buffers, the data is correctly freed in _FreeBuffers(). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27459 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp b/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp index e4a5b1376a..200f0a231a 100644 --- a/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp +++ b/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp @@ -212,7 +212,7 @@ MediaTrackAudioSupplier::_InitFromTrack() int64 MediaTrackAudioSupplier::_FramesPerBuffer() const { - int64 sampleSize = fFormat.u.raw_audio.format + int64 sampleSize = fFormat.u.raw_audio.format & media_raw_audio_format::B_AUDIO_SIZE_MASK; int64 frameSize = sampleSize * fFormat.u.raw_audio.channel_count; return fFormat.u.raw_audio.buffer_size / frameSize; @@ -229,7 +229,7 @@ MediaTrackAudioSupplier::_CopyFrames(void* source, int64 sourceOffset, void* target, int64 targetOffset, int64 position, int64 frames) const { - int64 sampleSize = fFormat.u.raw_audio.format + int64 sampleSize = fFormat.u.raw_audio.format & media_raw_audio_format::B_AUDIO_SIZE_MASK; int64 frameSize = sampleSize * fFormat.u.raw_audio.channel_count; source = (char*)source + frameSize * (position - sourceOffset); @@ -266,6 +266,8 @@ MediaTrackAudioSupplier::_AllocateBuffers() Buffer* buffer = new (nothrow) Buffer; if (!buffer || !fBuffers.AddItem(buffer)) { delete buffer; + if (fBuffers.CountItems() == 0) + delete[] data; return; } buffer->data = data; @@ -521,7 +523,7 @@ MediaTrackAudioSupplier::_ReadUncachedFrames(void* buffer, int64 position, } } // Ensure that all frames up to the next key frame are cached. - // This avoids, that each read + // This avoids, that each read if (error == B_OK) { int64 nextKeyFrame = currentPos; if (_FindKeyFrameForward(nextKeyFrame) == B_OK) {