diff --git a/content/media/webaudio/AudioBuffer.cpp b/content/media/webaudio/AudioBuffer.cpp index 04d6136224f..fc2c90b2f49 100644 --- a/content/media/webaudio/AudioBuffer.cpp +++ b/content/media/webaudio/AudioBuffer.cpp @@ -226,7 +226,7 @@ StealJSArrayDataIntoThreadSharedFloatArrayBufferList(JSContext* aJSContext, ? (uint8_t*) JS_StealArrayBufferContents(aJSContext, arrayBuffer) : nullptr; if (stolenData) { - result->SetData(i, stolenData, reinterpret_cast(stolenData)); + result->SetData(i, stolenData, js_free, reinterpret_cast(stolenData)); } else { return nullptr; } diff --git a/content/media/webaudio/AudioNodeEngine.h b/content/media/webaudio/AudioNodeEngine.h index 626d52dd834..2d30737ab1f 100644 --- a/content/media/webaudio/AudioNodeEngine.h +++ b/content/media/webaudio/AudioNodeEngine.h @@ -38,12 +38,16 @@ public: } struct Storage { - Storage() - { - mDataToFree = nullptr; - mSampleData = nullptr; + Storage() : + mDataToFree(nullptr), + mFree(nullptr), + mSampleData(nullptr) + {} + ~Storage() { + if (mFree) { + mFree(mDataToFree); + } else { MOZ_ASSERT(!mDataToFree); } } - ~Storage() { free(mDataToFree); } size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const { // NB: mSampleData might not be owned, if it is it just points to @@ -51,6 +55,7 @@ public: return aMallocSizeOf(mDataToFree); } void* mDataToFree; + void (*mFree)(void*); const float* mSampleData; }; @@ -67,11 +72,17 @@ public: * Call this only during initialization, before the object is handed to * any other thread. */ - void SetData(uint32_t aIndex, void* aDataToFree, const float* aData) + void SetData(uint32_t aIndex, void* aDataToFree, void (*aFreeFunc)(void*), const float* aData) { Storage* s = &mContents[aIndex]; - free(s->mDataToFree); + if (s->mFree) { + s->mFree(s->mDataToFree); + } else { + MOZ_ASSERT(!s->mDataToFree); + } + s->mDataToFree = aDataToFree; + s->mFree = aFreeFunc; s->mSampleData = aData; } diff --git a/content/media/webaudio/ConvolverNode.cpp b/content/media/webaudio/ConvolverNode.cpp index 1f14c555e4c..9937f3e6bb7 100644 --- a/content/media/webaudio/ConvolverNode.cpp +++ b/content/media/webaudio/ConvolverNode.cpp @@ -258,7 +258,7 @@ ConvolverNode::SetBuffer(JSContext* aCx, AudioBuffer* aBuffer, ErrorResult& aRv) for (uint32_t i = 0; i < data->GetChannels(); ++i) { PodCopy(channelData + length * i, data->GetData(i), mBuffer->Length()); PodZero(channelData + length * i + mBuffer->Length(), WEBAUDIO_BLOCK_SIZE - mBuffer->Length()); - paddedBuffer->SetData(i, (i == 0) ? channelData : nullptr, channelData); + paddedBuffer->SetData(i, (i == 0) ? channelData : nullptr, free, channelData); } data = paddedBuffer; } diff --git a/content/media/webaudio/PeriodicWave.cpp b/content/media/webaudio/PeriodicWave.cpp index 1d0e9a74a12..7a86f39cd4d 100644 --- a/content/media/webaudio/PeriodicWave.cpp +++ b/content/media/webaudio/PeriodicWave.cpp @@ -38,9 +38,9 @@ PeriodicWave::PeriodicWave(AudioContext* aContext, return; } PodCopy(buffer, aRealData, aLength); - mCoefficients->SetData(0, buffer, buffer); + mCoefficients->SetData(0, buffer, free, buffer); PodCopy(buffer+aLength, aImagData, aLength); - mCoefficients->SetData(1, nullptr, buffer+aLength); + mCoefficients->SetData(1, nullptr, free, buffer+aLength); } size_t