Skip to content

Dav1dFrameContext task_thread.cond leaks when n_threads==2

I believe the thread refactor (753eef83) introduced a leak of Dav1dFrameContext's task_thread.cond, as its creation relies on (c->n_tc > 1), and its destruction relies on (c->n_fc > 1), which are not guaranteed to simultaneously be true. When benchmarking libavif, I set dav1dSettings.n_threads = 2 and repeatedly created/destroyed dav1d contexts (as I was decoding many images one at a time), and eventually my (embedded) device ran out of conditions. I observed that c->n_tc == 2 (as I set n_threads = 2 at a higher level), but c->n_fc == 1, which skips the destroy of the cond.

I took a shot at fixing it, here:

joedrago/dav1d@cce2b056

I'm not confident enough in my understanding of dav1d_open()/dav1d_close() to be sure this properly solves this leak (or if there are others), but I'm happy to make this a proper PR if so. I suspect @psilokos and/or @rbultje are much better suited to tracking this one down.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information