Skip to content

Commit

Permalink
Fix rect release race condition in LayoutState
Browse files Browse the repository at this point in the history
Summary: Don't try to free the same rect multiple times, it could be acquired from the pool on another thread during iterations of this loop.

Reviewed By: IanChilds

Differential Revision: D6232924

fbshipit-source-id: 5aa76ae03fbcd7e8e2fda36e954de85c5d06e768
  • Loading branch information
astreet authored and facebook-github-bot committed Nov 3, 2017
1 parent 2c8c681 commit 30f6f58
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions litho-core/src/main/java/com/facebook/litho/LayoutState.java
Original file line number Diff line number Diff line change
Expand Up @@ -787,8 +787,11 @@ private static void collectResults(
rect.bottom = rect.top + node.getHeight();
}
for (Component delegate : node.getComponents()) {
layoutState.mComponentKeyToBounds.put(delegate.getGlobalKey(), rect);
final Rect copyRect = ComponentsPools.acquireRect();
copyRect.set(rect);
layoutState.mComponentKeyToBounds.put(delegate.getGlobalKey(), copyRect);
}
ComponentsPools.release(rect);
}

// All children for the given host have been added, restore the previous
Expand Down Expand Up @@ -1849,12 +1852,7 @@ void releaseRef() {
mDisplayListsToPrefetch.clear();

for (Rect rect : mComponentKeyToBounds.values()) {
// Delegate components are using the same Rect instance as the components they create since
// we don't calculate a layout output for them. We need to make sure we only release it
// once.
if (!rect.isEmpty()) {
ComponentsPools.release(rect);
}
ComponentsPools.release(rect);
}
mComponentKeyToBounds.clear();

Expand Down

0 comments on commit 30f6f58

Please sign in to comment.