Repository navigation
callback: Fix signal callback removal across nesting, recursion and registration (split from #1464) - #1556
Merged
Conversation
zackees
enabled auto-merge
October 20, 2026 20:19
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Oct 20, 2026
…tion and self-disconnect Supersedes the characterizations in nested_signal_test and global_remove_test and adds cases for deferred removal releasing the last handler reference, removal during recursive delivery, and removal after connects that move the callback array. Split from #1464.
…registration Squash of #1464's 00368fb, 183d3fd, 8bc9c00, 4554fee, 179e9a4: - release the handler when a deferred keep_ref removal drops the last ref - find global callbacks by callback and data, not a whole-struct memcmp - save and restore the thread-local current callback around delivery - count nested deliveries and erase removed callbacks only at depth 0 - track the current callback by signal and index, not a pointer into the array that a connect during delivery can reallocate
zackees
force-pushed
the
fix/signal-callbacks
branch
from
October 20, 2026 21:12
e6fb361 to
52ac191
Compare
zackees
enabled auto-merge
October 20, 2026 21:12
6 of 7 tasks
This was referenced Oct 21, 2026
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Oct 21, 2026
…#1639) * test: expect global callbacks tracked by index in signal (Refs obs-rust#1441) signal_handler_signal keeps a pointer into the global callback array while a global callback runs, and the running callback uses it for signal_handler_remove_current and the signaling count. Three cases move that entry while the pointer is held: - The callback connects enough global callbacks to reallocate the array, then removes itself (heap use-after-free, GHSA-rjwf-j53r-47qr). - A nested signal erases an earlier removed entry, then the outer callback removes itself. - The callback disconnects an earlier global callback, then removes itself. In the last two, the removal marks the next callback instead, and the pass skips that callback. The signal callbacks handle the same cases since obs-rust#1556. Build test_signal with ASan. Its allocator moves every reallocated block, so the first case does not depend on the platform allocator. libobs is not instrumented, so ASan does not report the write itself; the test sees the wrong result. Without ASan, glibc moves the array here too (5 of 5 runs fail). Refs obs-rust#1441 Co-Authored-By: Claude Opus 5.5 <[email protected]> * libobs: Track the running global callback by index (Refs obs-rust#1441) signal_handler_signal kept a pointer into the global callback array while a global callback ran. A connect from the callback could reallocate the array, and a nested signal or a disconnect could erase an earlier entry and move the running one. signal_handler_remove_current then wrote to freed memory or marked the next callback, and the signaling count went to the wrong entry. Follow the signal callbacks (obs-rust#1556): - The running global callback is a (handler, index) context. - The handler counts the running global passes. Removed entries are erased only when the outermost pass ends. - signal_handler_disconnect_global only marks the entry while a global pass runs. The per-entry signaling count is no longer needed and is removed. Refs obs-rust#1441 Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Oct 21, 2026
* test: add failing obs-callback signal tier 1 (Refs obs-rust#1441) Mirror test/cmocka/test_signal.c, as fixed by obs-rust#1556 and obs-rust#1639, against todo stubs in obs-callback. Add: global connect and disconnect matched by callback and data, a connect of many callbacks then remove_current from the running callback, a global signal in a nested pass, and a disconnect from another thread that waits for the running pass. From obs-rust#1639: a global callback that connects more global callbacks then removes itself, a nested pass that must not erase an earlier removed global callback, and a global disconnect during the pass. Refs obs-rust#1441 Co-Authored-By: Claude Opus 5.5 <[email protected]> * obs-callback: signal handler core in Rust (Refs obs-rust#1441) The safe core follows signal.c.h as fixed by obs-rust#1556 and obs-rust#1639: per-signal and global re-entrant locks held while callbacks run, deferred removal while signalling, keep_ref references, and the thread-local running callback. The running callback is a (signal, index) pair instead of a pointer into the callback array, so a connect from the callback cannot leave it dangling. As in the fixed C: - Passes of one signal nest by count, and so do the global passes. Removed callbacks are erased only when the outermost pass ends. A disconnect while a pass runs only marks the callback. The running global callback is an index, as the running signal callback is. - Each callback call saves and restores both running callbacks. A signal callback clears the global one, a global callback clears the signal one. remove_current marks the signal one first. - Global callbacks are found by callback and data only. - A keep_ref reference given back after a pass destroys the handler when it was the last one. signal() reports it to the owner. Refs obs-rust#1441 Co-Authored-By: Claude Opus 5.5 <[email protected]> * obs-callback: swap signal_handler to Rust (Refs obs-rust#1441) The ten signal_handler_* exports move into obs-callback. signal_handler_add_array stays inline in signal.h. The handle is one bmalloc block that holds an Arc, as in the audio-controls port, so bnum_allocs sees the handler until its last reference goes (keep_ref_remove_current_last_ref_test reads it). Both are freed when the C reference count reaches zero. signal_handler_signal keeps its own clone while callbacks run and frees the handler after the pass when the pass gave back the last reference. The log texts are the C ones. callback/signal.c moves into the ported group libobs.ported-callback, on its header. The audio-controls oracle defined signal_handler_connect and signal_handler_disconnect as stubs. A test binary that also links obs-callback, such as obs-tests-core, would define them twice (GNU ld stops). Rename the stubs to oracle_audio_controls_* with #define, as the oracle already does for its own exports. Tier 3 runs the original signal.c.h, as fixed by obs-rust#1639, on the decl oracle (oracle/signal.c). Random scripts of add, connect, connect_ref, disconnect, connect_global, disconnect_global and signal run with re-entrant actions. Signal callbacks remove the current one, disconnect or connect another, connect then remove, or start a nested signal. Global callbacks remove the current one, disconnect themselves, connect or disconnect another global callback, connect then remove, or start a nested signal. The test compares every callback call in order and every logged line. Excluded: a destroy from a callback (C frees the handler under the running pass). Against the core without the obs-rust#1639 rule, Tier 3 finds a failing script. Checks on Linux x86_64 (Debian 13), CMake with OBS_BUILD_C_REFERENCE: test_signal.c passes 19/19 against the hybrid libobs and against libobs-c-reference (loader checked). ctest against the hybrid passes 344/344 under xvfb-run, without the xcomposite/xshm tests that do not build on Debian's cmocka. obs-tests-core passes 422/422 with GNU ld. Refs obs-rust#1441 Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Split from #1464 (commits 00368fb, 183d3fd, 8bc9c00, 4554fee, 179e9a4, squashed into one GREEN commit). Part of breaking that 20-fix PR into small reviewable PRs. All changes are in
libobs/callback/signal.c.h; signal.c has no Rust port yet, so there is no Rust side to change (no parity test).What and why
signal_handler_connect_refcallback removed itself during delivery, the ref was dropped withos_atomic_set_long(refs - n), never checking for zero; if the creator had already calledsignal_handler_destroy, the handler was leaked. Now each ref is dropped withos_atomic_dec_longand the handler is destroyed on zero.da_find(memcmp of the whole entry) (183d3fd). The compare included padding and thesignalingcounter, so a global callback could not disconnect itself during delivery (signaling == 1), and connect/disconnect dedup depended on uninitialized padding. Now matched bycallbackanddata.signal_handler_signalset the thread-local current callback to NULL after each call, so a callback that emitted another signal and then calledsignal_handler_remove_current()removed nothing. Now the previous signal/global current callback is saved and restored.signallingwas a bool; an inner emission of the same signal erased removed callbacks while the outer loop was still walking the array, so the outer pass skipped later subscribers. Now a depth counter; removal happens only when the outermost pass finishes.signal_handler_remove_current()wrote into freed memory (ASan: heap-use-after-free insignal_handler_remove_current) and did not remove itself. Now tracked as (signal, index), and the callback entry is copied before the call.This deliberately changes characterization tests in
test/cmocka/test_signal.c, following the precedent of #1508 (the C-test expectation change was approved by the maintainer as in #1508). Assertions are stricter, comments say the old characterization is superseded and why. No assertion was removed or weakened.nested_signal_test(fixturenested_then_remove)innerstill deliversglobal_remove_testglobal_testkeep_ref_remove_current_last_ref_test(#1)bnum_allocsback to baseline) when the last ref is a self-removing keep_ref callbackrecursive_remove_test(#4)connect_then_remove_current_test(#5)RED → GREEN
Built
test_signal.clocally againstsignal.c.h/calldata.c.h/decl.c.hand the util sources with a minimal cmocka shim (with and without ASan); the full Docker Tier 2 is left to PR CI per shared-machine rules.nested_signal_test(count 4 != 2),keep_ref_remove_current_last_ref_test(allocs 11 != 7),recursive_remove_test(4 != 5),connect_then_remove_current_test(2 != 1; ASan: heap-use-after-free),global_remove_test(3 != 2)../lintok.Checklist
masterdocs/features.mdlines added (Stability), wording from fix: 20 bug fixes in libobs callbacks, muxer, audio and build #1464