pa_stream_disconnect() is broken
@tanuk
Submitted by Tanu Kaskinen Assigned to pul..@..op.org
Description
pa_stream_disconnect() doesn't work in all situations. In at least two situations it's clearly broken:
-
When it's called while the stream state is CREATING, s->channel_valid is false, which causes the function to return with -PA_ERR_BADSTATE. The stream creation isn't cancelled, contrary to what would be the expected behaviour.
-
Normally, when an application calls pa_stream_disconnect() while the stream state is FAILED, the function will return with -PA_ERR_BADSTATE because s->channel_valid is false. However, when the stream state is just changing to FAILED, and the application calls pa_stream_disconnect() from the stream state callback, channel_valid has not yet been set to false, and the function continues as if everything is fine. This can reportedly result in a crash, although I haven't investigated this enough to explain the exact cause of the crash.
pa_stream_disconnect() works asynchronously, which I believe is a bad idea. I think it would be better if pa_stream_disconnect() would immediately cancel all in-flight operations, reset the stream object to a safe state, and finally notify the application that the state changed to TERMINATED. pa_stream_disconnect() could then become a void function that is safe to call in all situations, like pa_context_disconnect() is.