Skip to content

Commit 156454e

Browse files
joevilchesfacebook-github-bot
authored andcommitted
Potentially fix seg fault when replace YogaLayoutableShadowNodes (facebook#47689)
Summary: Pull Request resolved: facebook#47689 We were seeing some segfaults from trying to access `display_` in Yoga's `replaceChild` function. Some memory debugging helped identify this was a use-after-free error and NickGerleman suggested we try swapping these lines. Logic being the shared_ptr of YogaLayoutableShadowNode is replaced right before we go and replace its yoga node in the yoga tree. If this is the last shared_ptr holding this node we will delete this object and thus the yoga node with it. We do not need to do this first, so let's swap the lines. Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D66142356 fbshipit-source-id: 8fd835346edc91e045ed2ee8945a95af21c47556
1 parent fa65b93 commit 156454e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,13 @@ void YogaLayoutableShadowNode::replaceChild(
300300
// Both children are layoutable, replace the old one with the new one
301301
react_native_assert(layoutableNewChild->yogaNode_.getOwner() == nullptr);
302302
layoutableNewChild->yogaNode_.setOwner(&yogaNode_);
303-
*oldChildIter = layoutableNewChild;
304303
yogaNode_.replaceChild(&layoutableNewChild->yogaNode_, oldChildIndex);
304+
*oldChildIter = layoutableNewChild;
305305
} else {
306306
// Layoutable child replaced with non layoutable child. Remove the previous
307307
// child from the layoutable children list.
308-
yogaLayoutableChildren_.erase(oldChildIter);
309308
yogaNode_.removeChild(oldChildIndex);
309+
yogaLayoutableChildren_.erase(oldChildIter);
310310
}
311311

312312
ensureYogaChildrenLookFine();

0 commit comments

Comments
 (0)