Commit 00e18da
Fix potential race conditions when executing commitHooks (#53862)
Summary:
Recently we saw `use-after-free race condition` where the ImageFetcher object was being destroyed while still registered as a UIManagerCommitHook.
The crash occurred in `std::vector::size()` at line 635 when accessing corrupted memory.
The root cause could be improper lifecycle management between ImageFetcher destruction and commit hook execution.
The fix here modifies `UIManager::shadowTreeWillCommit()` to create a stable snapshot by copying the commitHooks_ vector while holding the lock.
## Reason
- If a thread is iterating over `commitHooks_` with a `shared_lock`, and another thread acquires a `unique_lock` to modify the vector (add/remove), the iterator in the first thread can become invalid, leading to a crash (use-after-free or out-of-bounds).
- This can happen if the lock is not held for the entire duration of the read or write, or if the lock is not correctly used everywhere commitHooks_ is accessed.
Changelog: [Internal]
Differential Revision: D828462451 parent 362ed17 commit 00e18da
File tree
1 file changed
+6
-2
lines changed- packages/react-native/ReactCommon/react/renderer/uimanager
1 file changed
+6
-2
lines changedLines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
615 | 615 | | |
616 | 616 | | |
617 | 617 | | |
618 | | - | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
619 | 623 | | |
620 | 624 | | |
621 | | - | |
| 625 | + | |
622 | 626 | | |
623 | 627 | | |
624 | 628 | | |
| |||
0 commit comments