-
Notifications
You must be signed in to change notification settings - Fork 349
Audio: Fix Memory Leaks in Buffer Component Release #10052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
tmleman
wants to merge
5
commits into
thesofproject:main
from
tmleman:topic/upstream/pr/fix/mem_leak/buffer_free
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c1c890f
audio: copier: fix memory leak in copier_dai_free
tmleman 7e70394
ipc3: fix memory leak in ipc_buffer_new
tmleman 98a1151
audio: fix memory leak in chain_dma buffer handling
tmleman d6d8e98
audio: resolve buffer memory leaks in legacy reset functions
tmleman bfcaba5
audio: complete dma_buffer deallocation in Zephyr components
tmleman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks wrong to me. Looking at
buffer_free()sof/src/include/sof/audio/buffer.h
Lines 236 to 239 in 97f869c
and then in
audio_buffer_free()sof/src/audio/buffers/audio_buffer.c
Line 97 in 97f869c
struct comp_buffersof/src/include/sof/audio/buffer.h
Lines 126 to 128 in 97f869c
rfree(buffer)inaudio_buffer_free()isn't a good idea, becauseaudio_buffer_free()isn't called on a whole object, that can be freed, but on a member of an object. (2) that does however happen to work because that member is currently the first in the object, so its address is equal to the address of the object, so it ends up freeing the object, (3) these fixes aren't correct because the buffer is indeed freed bybuffer_free()because of the above. So, this PR isn't fixing a problem but in fact adding a double free bug, insteadaudio_buffer_free()and / orbuffer_free()should be fixed to clarify which one frees the underlying buffer memory.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not really. The main object is
struct sof_audio_buffer, a base class for all buffers (currentlycomp_bufferandring buffer)in c++ it would be simple and clear
also freeing would be obvious by using virtual destructors
but we're using an obsolete C, so we need to put sof_audio_buffer as a member :(
this part:
static inline void buffer_free(struct comp_buffer *buffer) { audio_buffer_free(&buffer->audio_buffer); }is just a wrapper. Although sof_audio_buffer should be used (what would make possible using comp_buffer and ring_buffer - and other buffers - directly in a pipeline), yet some code is still using comp_buffer as a main structure (with unfortunate double buffering when ring_buffer is needed)