Repository navigation
Resource manager: free a data stream's file path when a synchronous init fails - #1176
Merged
Merged
Conversation
Owner
|
Look reasonable. Merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resource manager: free a data stream's file path when a synchronous init fails
Summary
On
dev-0.12(but not ondev),ma_resource_manager_data_stream_init_ex()copies the file path into the data stream (pFilePath/pFilePathW), and onlyma_resource_manager_data_stream_uninit()frees that copy. A caller doesn't uninitialize a data stream that failed to initialize, and neither doesma_sound. So when a synchronous (orWAIT_INIT) init fails, for example because the file isn't audio, the copy leaks.The leak was introduced by b73f018 ("Add support for copying data streams"), which is only on
dev-0.12. Before it, and still ondevand in 0.11.25, the path copy goes to the load job, which frees it whether the load succeeds or fails. b73f018 moved the copy into the data stream so thatma_resource_manager_data_stream_init_copy()can reuse it, and left freeing it to uninit.The fix
In
ma_resource_manager_data_stream_init_ex(), on the error path after waiting for the load job: freepFilePathandpFilePathW, and set them toNULL.The load job only reads the path while initializing the decoder, which it does before it signals the init notification. So by the time the init has waited on that notification, the job is done with the path.
The asynchronous path is unchanged. There, an init that fails later still leaves the caller with a data stream to uninitialize, and uninit frees the path as before.
Reproduction
Before, on b6df52c:
After:
Invalid file, and no leak.ma_sound_init_from_file()withMA_SOUND_FLAG_STREAMleaks the same way, once per failed init.Disclosure
The bug was found and fixed with the help of Claude, and it also helped create this PR description.
Licensing
I am ok with the code being put in the public domain.