[pulseaudio-discuss] [patch] ops: catch repeated finalisation

Tanu Kaskinen tanuk at iki.fi
Mon Jul 16 09:50:40 UTC 2018


On Thu, 2018-07-05 at 05:16 +0100, jnqnfe at gmail.com wrote:
> The internal operation_set_state function already returns early if the
> new state is the same as the existing state. The attached patch extends
> this to return early if already in a finalised (done/cancelled) state,
> i.e. blocks attempts to re-finalise into a different state.
> 
> This helps avoid unlinking more than once (or crashing on ref count
> assertion).
> 
> I was not certain whether an assertion would be a better alternative -
> with such a crash helping highlight usage problems...
> 
> The situation that lead to this was the thought of someone stupidly
> trying to pa_operation_cancel() a callback within the callback
> execution itself, while designing a solution for a memory leak related
> to cancellation within my Rust binding. While no-one should do such a
> thing, if they did, they'd either trip up a ref count assertion, or the
> operation would be unlinked twice, which would be bad. It's a simple
> thing to catch and mitigate, and could prove to be a useful
> bulletproofing measure for this function in general.

Thanks! This seems like a good approach to the problem. I applied the
patch. Please write the change rationale to the commit message in the
future. I copied your explanation to the commit message myself.

-- 
Tanu

https://www.patreon.com/tanuk
https://liberapay.com/tanuk


More information about the pulseaudio-discuss mailing list