Make sure FilterAudioStream is alive in callbacks (#2325)#2354
Make sure FilterAudioStream is alive in callbacks (#2325)#2354jg-hot wants to merge 1 commit intogoogle:mainfrom
Conversation
|
@flamme @robertwu1 could you please review this when you get a chance? I'm not able to add reviewers directly. Thanks. |
|
LGTM @flamme please add comments if you have any. Thanks! |
| // callbacks are routed through it. | ||
| std::shared_ptr<AudioStream> sharedParentStream; | ||
| if (sharedStream && sharedStream->hasParentStream()) { | ||
| sharedParentStream = sharedStream->getParentStream()->lockWeakThis(); |
There was a problem hiding this comment.
Q: this parent stream is a raw pointer, how it guarantees the parent stream is still alive when a callback arrive?
There was a problem hiding this comment.
This relies on the same assumption that the AAudioStreamCollection uses for the child (AAudio) stream. That the client always calls close() before releasing their shared_ptr.
That ensures that callbacks are rejected if the stream is about to be released.
The parent should be alive as long as the child is. The ownership chain is shared_ptr client → FilterAudioStream → AudioStreamAAudio.
I don't see any case where the parent is freed but the child is not.
There was a problem hiding this comment.
Isn't the root cause that the parent stream is gone while the child stream is still alive? The child stream received an error callback and call to parent's error callback, which was swapped in FilterAudioStream constructor.
This modifies
AAudioStreamCollection.getStream()to return a tuple which includes ashared_ptrto the parent stream if theAAudioStreamis wrapped by aFilterAudioStream.The child is linked to the parent via a raw pointer (
AudioStream.getParentStream()/AudioStream.hasParentStream()and locked during callbacks withlockWeakThis().The
shared_ptrto the parent is passed to the callback threads (e.g.oboe_aaudio_error_thread_proc_shared) so its memory is retained until the callback thread finishes running.See discussion under issue #2325 for more details.
Tested against the sample in FilterAudioStreamUAF-repro.