fix crash on corrupted transition name#1703
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens transition tracking in CallbackManager::addSource to prevent crashes when transition names are corrupted/duplicated, by ensuring map ownership is established before signal connections and by avoiding std::string(nullptr) construction.
Changes:
- Adds a null-guard around
obs_source_get_name()for transitions before logging and key construction. - Reworks transition insertion to use
std::unique_ptr+try_emplace, connecting signal handlers only when insertion succeeds and using the map-owned pointer as callback userdata. - Logs a warning when a transition with the same name is already tracked.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
sandboxcoder
approved these changes
May 21, 2026
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.
Description
Net change: addSource for transitions now owns ti via unique_ptr from the start, calls try_emplace before connecting any signal handlers, and connects only if insertion actually happened — using result.first->second.get() (the map-owned pointer) as the user-data. On duplicate, the local unique_ptr destructs cleanly, no handlers ever reference a freed TransitionInfo, and a warning is logged so the situation is visible in the next dump.
Also adds a NULL-guard on obs_source_get_name — kills the std::string(nullptr) UB that was a third trigger for the same crash path.
Motivation and Context
How Has This Been Tested?
Types of changes
Checklist: