Skip to content

bug: libobs: obs_encoder_set_group(enc, NULL) leaves a stale group pointer on the encoder #483

Closed

Description

@chriscoveries

Summary

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:

  1. obs_encoder_set_group(enc, first)
  2. obs_encoder_set_group(enc, NULL)
  3. obs_encoder_set_group(enc, second)
  4. 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.

Activity

  1. zackees commented on Oct 13, 2026

    @zackees
    Member

    @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.

  2. added
    claimed
    on Oct 13, 2026
  3. chriscoveries commented on Oct 14, 2026

    @chriscoveries
    ContributorAuthor

    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.

  4. zackees commented on Oct 14, 2026

    @zackees
    Member

    Claiming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    claimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions