You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: libobs: obs_encoder_set_group(enc, NULL) leaves a stale group pointer on the encoder #483
Removing an encoder from its group with obs_encoder_set_group(encoder, NULL) drops the group's reference but keeps encoder->encoder_group pointing at the old group. A later obs_encoder_set_group(encoder, other) then releases an encoder reference the encoder no longer holds, so the encoder can be destroyed while the new group still lists it. Severity: medium for plugin authors and frontends that move encoders between groups, since the failure is a use-after-free of the encoder.
Steps / trigger
Public API only, with a video encoder you hold a reference to:
obs_encoder_set_group(enc, first)
obs_encoder_set_group(enc, NULL)
obs_encoder_set_group(enc, second)
Drop your own references to enc.
The second group's reference should keep the encoder alive. It does not, because step 3 released a reference the encoder did not own.
Cause
Line numbers are against current master.
libobs/obs-encoder.c:2262-2274: when encoder->encoder_group is set, the function erases the encoder from the old group (:2271) and calls obs_encoder_release(encoder) (:2272), but never clears encoder->encoder_group.
libobs/obs-encoder.c:2276-2277: with group == NULL the function then returns true, leaving the stale pointer.
On the next call, :2262-2274 runs again against that stale group: nothing is erased, but obs_encoder_release runs a second time.
The stale pointer is also read by the start and stop paths (:387-404, :425-427), so it dangles if the old group has been destroyed. I did not exercise that path. The encoder group code is C only, so ON and OFF behave the same.
Proposed fix
Set encoder->encoder_group = NULL after the da_erase_item and before obs_encoder_release in the leave-old-group block. The regression test uses the public API, takes two references and a weak reference, runs the three set_group calls above, and checks with obs_weak_encoder_get_encoder() that the encoder is still alive while the second group holds it.
I'd like to work on this; a fix with a regression test is ready.
@chriscoveries go ahead: please open the PR with the RED test commit first, then the fix (one PR per issue, targeting master). Marking it claimed for you.
Releasing this one. We're backed up on CI and won't get it landed soon, so anyone who wants it is welcome to take it.
If it helps, our RED test and fix are on the fork branch fix/encoder-group-clear-on-remove. They passed review on our side but haven't been through CI, so reuse them or start fresh, whichever you prefer.
Activity
zackees commentedon Oct 13, 2026
@chriscoveries go ahead: please open the PR with the RED test commit first, then the fix (one PR per issue, targeting master). Marking it claimed for you.
chriscoveries commentedon Oct 14, 2026
Releasing this one. We're backed up on CI and won't get it landed soon, so anyone who wants it is welcome to take it.
If it helps, our RED test and fix are on the fork branch
fix/encoder-group-clear-on-remove. They passed review on our side but haven't been through CI, so reuse them or start fresh, whichever you prefer.zackees commentedon Oct 14, 2026
Claiming.
libobs: clear encoder_group on obs_encoder_set_group(enc, NULL) (#688)