Repository navigation
Description
What
test/cmocka/test_hotkey_binding_press_steps (from #3032, merged as 93b5e64db) fails on the macOS Tier 2 lane. It is the only failing test in the lane (382/383 pass), it is not flaky-looking, and no PR has run that lane since the test landed, because PR CI only selects macOS Tier 2 when the change is in scope: this was found by a workflow-only PR that selects it.
Run: https://github.com/obs-rust/obs-studio/actions/runs/41036571990/job/123998913951 (PR #3042, head c6a527ee6, master 5fe22f01c)
222/383 Test #224: test_hotkey_binding_press_steps .................***Failed
[ RUN ] remove_bindings_releases
[ ERROR ] --- 1 != 2
[ LINE ] --- test/cmocka/test_hotkey_binding_press_steps.c:317: error: Failure!
[ FAILED ] remove_bindings_releases
Line 317 is assert_int_equal(num_calls, 2) right after obs_hotkey_unregister(id). The two presses did count (hotkey->pressed == 2 at line 312 passed); the release calls did not happen at unregister.
Root cause
libobs/obs-hotkey.c.h, unregister_hotkey():
HASH_DEL(obs->hotkeys.hotkeys, hotkey);
hotkey_signal("hotkey_unregister", hotkey);
release_registerer(hotkey);
if (hotkey->registerer_type == OBS_HOTKEY_REGISTERER_SOURCE)
obs_weak_source_release(hotkey->registerer);
bfree(hotkey->name);
bfree(hotkey->description);
bfree(hotkey); /* hotkey is freed here */
remove_bindings(id); /* ... and remove_bindings() releases bindings */remove_bindings() (:798) calls obs_hotkey_binding_release(binding) for every pressed binding it removes, and that wrapper reads binding->hotkey->pressed through obs_hotkey_binding_count_fields(). The hotkey it dereferences was bfreed four lines earlier: a use-after-free.
Linux passes because the freed block still holds pressed = 2, so the release runs the callback; macOS's allocator reuses/poisons the block, the count reads as 0, the release sees "already released" and no callback runs, hence one call short. The test is right and the code is wrong: a binding release after the hotkey is gone is exactly the case remove_bindings() exists to handle, and it currently reads freed memory on every platform (it is only silently benign where the allocator happens not to reuse the block).
Note this ordering matches upstream OBS, so it is an upstream latent defect that surfaced here, not a fork regression.
Why it matters beyond the test
obs_hotkey_unregister() is the path for source, output, encoder and frontend hotkeys going away. Every unregister of a hotkey that has a pressed binding does the same read-after-free; the observable effect is a missing "released" callback (a hotkey that stays down for the app), and under ASan it is a straight use-after-free report.
Fix
Move remove_bindings(id) before the frees in unregister_hotkey(), so bindings are released while the hotkey is still alive:
HASH_DEL(obs->hotkeys.hotkeys, hotkey);
hotkey_signal("hotkey_unregister", hotkey);
release_registerer(hotkey);
if (hotkey->registerer_type == OBS_HOTKEY_REGISTERER_SOURCE)
obs_weak_source_release(hotkey->registerer);
remove_bindings(id);
bfree(hotkey->name);
bfree(hotkey->description);
bfree(hotkey);The RED is already recorded above (macOS Tier 2, line 317); the GREEN is the same lane. A Linux asan build of test_hotkey_binding_press_steps should also report the use-after-free before the fix, which is worth recording in the fix PR.
Class: libobs lifetime bug (use-after-free), reachable from every unregister path. Not remote-reachable: it needs a local hotkey registration, so it is a normal public bug per SECURITY.md.
Activity
zackees commentedon Oct 30, 2026
Claiming: #3044 — release the bindings before the hotkey is freed.
test_hotkey_binding_press_steps/remove_bindings_releasesfails on macOS Tier 2 (1 != 2at line 317) becauseremove_bindings()readsbinding->hotkey->pressedfrom the blockunregister_hotkey()freed four lines earlier.remove_bindings(id)above the frees inunregister_hotkey()(libobs/obs-hotkey.c.h), so every pressed binding of the hotkey is released while the hotkey is alive. No test edits: the new characterization test is the failing test.zackees commentedon Oct 30, 2026
Fixed and merged.
908595e00(libobs: release a hotkey's bindings before the hotkey is freed). Merge-group run 41045378895 is green (CI Gate ✅; macOS Tier 2 skipped there by scope).remove_bindings(id)moved ahead of thebfrees inunregister_hotkey(), soobs_hotkey_binding_release()readsbinding->hotkey->pressedwhile the hotkey is alive instead of after it was freed.Evidence:
scheduled.yamlrun 41039924489,Build 🧱 / Rust Tier 2 (macos-26)passed,test_hotkey_binding_press_stepsremove_bindings_releasesgreen.Build 🧱 / Sanitize 🧪 / asan 🧪success;test_hotkey_binding_press_stepsexit=0 and the sanitizer triage lists noobs-hotkeyfinding — the use-after-free is gone. App launchapp exit=0; the listed leaks/UBSan reports are the lane's existing set, unrelated to this path.What is left:
docs/features.mdline that this user-visible upstream-bug fix should have carried in the same PR was missed. #3057 adds it under Fixed upstream bugs → Stability (docs only).libobs: release a hotkey's bindings before the hotkey is freed (obs-r…
docs: ledger line for the hotkey unregister release fix (obs-rust#3044)…