Skip to content

bug: libobs: obs_shutdown() segfaults when called after obs_startup() failed #1032

Closed

Description

@zackees

Seen in a local Tier 2 run (OFF build, 2026-10-16 ~07:30Z) in test_media_restart_stale_frame clear_still_clears, listed on #838 as a flake. The log shows it is not timing:

info: Unable to open X display
info: Freeing OBS context data
[  ERROR   ] --- Test failed with exception: Segmentation fault(11)
[  FAILED  ] clear_still_clears

The test's init_core() (test/cmocka/test_media_restart_stale_frame.c:134) calls obs_startup then obs_reset_video; the latter failed (the X server under xvfb-run -a was not reachable for that one case, the previous case in the same binary passed). run_script then does the right thing, obs_shutdown(); skip(); (:413-415), and the crash happens inside that obs_shutdown() ("Freeing OBS context data" is printed by it, the segfault right after).

Class

Crash in teardown after a failed video init. Any caller that handles an obs_reset_video failure and shuts down cleanly (an app on a machine whose GPU/display fails, or a test) crashes instead of exiting.

Next steps

  1. Failing test: obs_startup, obs_reset_video with an unreachable display (e.g. DISPLAY=:9999, or a bogus graphics_module), expect a non-success result, then obs_shutdown(): must not crash. Run in the Tier 2 container.
  2. Find which teardown step touches state the failed reset left half-initialized (graphics thread, video output, or canvas), and guard it.

Refs #838 (this entry there is a crash, not load sensitivity).

Activity

  1. added
    bug
    on Oct 16, 2026
  2. zackees commented on Oct 16, 2026

    @zackees
    MemberAuthor

    Seen again (ON build, ~08:10Z): clear_then_frame_unbuffered segfaulted after "Unable to open X display". The trigger is Xvfb intermittently unreachable under parallel ctest (noted on #838); the crash in obs_shutdown() after a failed obs_reset_video() is the libobs bug this issue tracks.

  3. zackees commented on Oct 16, 2026

    @zackees
    MemberAuthor

    Claiming: RED test (obs_startup, obs_reset_video against an unreachable DISPLAY so it fails deterministically, then obs_shutdown must not crash), then find and guard the teardown step.

  4. added
    claimed
    on Oct 16, 2026
  5. zackees commented on Oct 16, 2026

    @zackees
    MemberAuthor

    Update: my first reproduction does not crash. DISPLAY=:9999, obs_startup, obs_reset_video (fails as expected), obs_shutdown passes in Tier 2 (branch fix/1032-shutdown-after-failed-video, commit ea1ad596f). So "shutdown after any failed video reset" is not the bug.

    What the failing logs actually show is "Unable to open X display", then Freeing OBS context data, then the segfault. "Unable to open X display" can also come from obs_startup's X11 hotkey/platform setup, so in the real failures the X connection may have failed in one place but not another (e.g. hotkeys lost the display while graphics came up), which a dead :9999 can't produce. The crash is late in or after obs_shutdown. Next: get a backtrace by running test_media_restart_stale_frame with the display dropped mid-start (or under catchsegv/gdb in the Tier 2 container), instead of guessing further. Keeping the claim.

  6. zackees commented on Oct 16, 2026

    @zackees
    MemberAuthor

    Correction to my earlier comment: "Unable to open X display" is not evidence that Xvfb was unreachable. It is printed by obs_nix_x11_log_info() (libobs/obs-nix-x11.c:39) whenever obs_get_nix_platform_display() is NULL, i.e. whenever nothing called obs_set_nix_platform_display(), which only the frontend does. Every cmocka test that calls obs_startup logs it, including passing ones (the next test_v4l2_busy_signal case logged it and then registered X11 hotkey keycodes fine). So the "Xvfb dropping out under parallel ctest" explanation I gave is wrong and should be disregarded; the cause of these failures is still unknown. For this issue: the segfault after Freeing OBS context data is real, but I don't yet know what precedes it; next step is still a backtrace.

  7. zackees commented on Oct 16, 2026

    @zackees
    MemberAuthor

    Found it. The crashes are obs_shutdown() after a failed obs_startup(), not after a failed video reset. In the crashing cases the log is CPU info, "Unable to open X display" (harmless, see above), then Freeing OBS context data with no video settings reset lines: that is obs_startup() failing and cleaning up after itself (it calls obs_shutdown() internally, libobs/obs.c:~1408, leaving obs NULL). The test's init_core() returns false and its error path calls obs_shutdown() again, which dereferences obs->source_types with no NULL check. On Linux obs_startup() fails when its X11 hotkey connection (XOpenDisplay in obs_nix_x11_hotkeys_platform_init) can't be opened, which is what happened transiently in those runs.

    My earlier "passing" repro never tested this: with DISPLAY=:9999 its obs_startup() failed and the test skip()ped, which cmocka counts as a pass. The new RED test asserts the startup failure instead and then calls obs_shutdown(). Fix: make obs_shutdown() a no-op without a core (if (!obs) return;), like obs_reset_video already does.

  8. changed the title [-]bug: libobs: obs_shutdown() segfaults after obs_reset_video() failed (no X display)[/-] [+]bug: libobs: obs_shutdown() segfaults when called after obs_startup() failed[/+] on Oct 16, 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

    bugclaimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions