From e446815189f0db7f63aeb70e9eea66bfece34e40 Mon Sep 17 00:00:00 2001 From: David Volgyes Date: Fri, 29 Jul 2011 13:54:21 +1200 Subject: [PATCH] Bug 673154 - Use nsAutoArrayPtr for SoundDataValue allocations to simplify ownership. r=cpearce --- content/media/ogg/nsOggReader.cpp | 15 +++++++-------- content/media/webm/nsWebMReader.cpp | 15 +++++++-------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/content/media/ogg/nsOggReader.cpp b/content/media/ogg/nsOggReader.cpp index b8efc60628e1..0a8ebb971226 100644 --- a/content/media/ogg/nsOggReader.cpp +++ b/content/media/ogg/nsOggReader.cpp @@ -369,7 +369,7 @@ nsresult nsOggReader::DecodeVorbis(ogg_packet* aPacket) { ogg_int64_t endSample = aPacket->granulepos; while ((samples = vorbis_synthesis_pcmout(&mVorbisState->mDsp, &pcm)) > 0) { mVorbisState->ValidateVorbisPacketSamples(aPacket, samples); - SoundDataValue* buffer = new SoundDataValue[samples * channels]; + nsAutoArrayPtr buffer(new SoundDataValue[samples * channels]); for (PRUint32 j = 0; j < channels; ++j) { VorbisPCMValue* channel = pcm[j]; for (PRUint32 i = 0; i < PRUint32(samples); ++i) { @@ -379,13 +379,12 @@ nsresult nsOggReader::DecodeVorbis(ogg_packet* aPacket) { PRInt64 duration = mVorbisState->Time((PRInt64)samples); PRInt64 startTime = mVorbisState->Time(endSample - samples); - SoundData* s = new SoundData(mPageOffset, - startTime, - duration, - samples, - buffer, - channels); - mAudioQueue.Push(s); + mAudioQueue.Push(new SoundData(mPageOffset, + startTime, + duration, + samples, + buffer.forget(), + channels)); endSample -= samples; if (vorbis_synthesis_read(&mVorbisState->mDsp, samples) != 0) { return NS_ERROR_FAILURE; diff --git a/content/media/webm/nsWebMReader.cpp b/content/media/webm/nsWebMReader.cpp index efd513bfd8e9..5ff68ef82bb2 100644 --- a/content/media/webm/nsWebMReader.cpp +++ b/content/media/webm/nsWebMReader.cpp @@ -484,7 +484,7 @@ PRBool nsWebMReader::DecodeAudioPacket(nestegg_packet* aPacket, PRInt64 aOffset) VorbisPCMValue** pcm = 0; PRInt32 samples = 0; while ((samples = vorbis_synthesis_pcmout(&mVorbisDsp, &pcm)) > 0) { - SoundDataValue* buffer = new SoundDataValue[samples * mChannels]; + nsAutoArrayPtr buffer(new SoundDataValue[samples * mChannels]); for (PRUint32 j = 0; j < mChannels; ++j) { VorbisPCMValue* channel = pcm[j]; for (PRUint32 i = 0; i < PRUint32(samples); ++i) { @@ -505,13 +505,12 @@ PRBool nsWebMReader::DecodeAudioPacket(nestegg_packet* aPacket, PRInt64 aOffset) PRInt64 time = tstamp_usecs + total_duration; total_samples += samples; - SoundData* s = new SoundData(aOffset, - time, - duration, - samples, - buffer, - mChannels); - mAudioQueue.Push(s); + mAudioQueue.Push(new SoundData(aOffset, + time, + duration, + samples, + buffer.forget(), + mChannels)); mAudioSamples += samples; if (vorbis_synthesis_read(&mVorbisDsp, samples) != 0) { return PR_FALSE;