Skip to content

libobs: pthread init failures are checked with < 0 and never caught #2152

Closed

Description

@rdoupe

Bug

Three pthread initializations check for failure with < 0. The pthread functions return a positive error number on failure, never a negative one, so these failures are never caught:

  • libobs/obs.c.h: obs_context_data_init_wrap() checks pthread_mutex_init(&context->rename_cache_mutex, NULL) < 0. If the init fails, the context carries on with an uninitialized mutex.
  • libobs/util/threading-posix.c: os_event_init() checks pthread_mutex_init(...) < 0 and pthread_cond_init(...) < 0. On failure it returns 0 and hands back an event whose mutex or condition variable is uninitialized.

These inits almost never fail on Linux or macOS, so this is a robustness fix: under resource exhaustion, a failed init should fail the creation cleanly instead of leaving a lock that isn't valid. Upstream has the same code; the first dates from 2014. Found while fixing #2141.

Plan

  1. RED: a cmocka test that makes pthread_mutex_init and pthread_cond_init fail on demand, as test_canvas_flags (libobs: Canvases accept the internal REMOVED flag and unknown bits; leak when context init fails #2141) does, and checks two things:

    • os_event_init() returns non-zero, leaves the out-pointer unset, and leaks nothing;
    • creating a context-backed object fails cleanly when the rename cache mutex can't be initialized.

    This runs on the C libobs and libobs-c-reference. The hybrid libobs's Rust os_event_init gets a parity check that it already reports failure.

  2. GREEN: check != 0 in all three places. The error paths that follow stay the same.

Activity

  1. rdoupe commented on Oct 24, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: #2152.

  2. added
    claimed
    on Oct 24, 2026
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