Fix a leak on allocation failure in AudioDataResource creation
Categories
(Core :: Audio/Video: Web Codecs, task)
Tracking
()
People
(Reporter: Sylvestre, Unassigned, Mentored)
References
(Blocks 1 open bug)
Details
(Keywords: good-first-bug, Whiteboard: [lang=c++])
Filing as a good first bug to learn workflows.
new AudioDataResource() is stored in a raw pointer; when the following fallible AppendElements fails the object leaks and a null resource is returned to the caller. Hold it in a RefPtr (it is refcounted) and return it with .forget() on success.
Current code:
static AudioDataResource* Create(const Span<uint8_t>& aData) {
AudioDataResource* resource = new AudioDataResource();
if (!resource->mCopiedData.AppendElements(aData, mozilla::fallible_t())) {
Link to the code:
https://searchfox.org/firefox-main/source/dom/media/webcodecs/AudioData.h
To verify the fix:
./mach build
./mach test dom/media/webcodecs/test --headless
This was reported by Coverity Scan (CID 1592978). The analyzer will stop reporting it once the change lands.
Tutorial to contribute:
https://firefox-source-docs.mozilla.org/contributing/contribution_quickref.html
https://firefox-source-docs.mozilla.org/contributing/stack_quickref.html
Please don't ask for the bug to be assigned. It will be automatically assigned to the first patch.
Description
•