Skip to content

Commit 9287786

Browse files
javachemeta-codesync[bot]
authored andcommitted
Fix leak in PointerEvent (#54374)
Summary: Pull Request resolved: #54374 `eventState` retains a `hitPath` which may retain views, so will leak if not cleaned up. Changelog: [Internal] Reviewed By: lenaic Differential Revision: D86091939 fbshipit-source-id: 8eb6c3f55cefa176430b6e05c414be9aeeed460d
1 parent a034841 commit 9287786

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/PointerEvent.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal class PointerEvent private constructor() : Event<PointerEvent>() {
2929
private lateinit var _eventName: String
3030
private var coalescingKey = UNSET_COALESCING_KEY
3131
private var pointersEventData: List<WritableMap>? = null
32-
private lateinit var eventState: PointerEventState
32+
private var eventState: PointerEventState? = null
3333

3434
private fun init(
3535
eventName: String,
@@ -84,7 +84,7 @@ internal class PointerEvent private constructor() : Event<PointerEvent>() {
8484
return@EventAnimationDriverMatchSpec false
8585
}
8686
if (isBubblingEvent(eventName)) {
87-
for (viewTarget in eventState.hitPathForActivePointer) {
87+
for (viewTarget in checkNotNull(eventState).hitPathForActivePointer) {
8888
if (viewTarget.getViewId() == viewTag) {
8989
return@EventAnimationDriverMatchSpec true
9090
}
@@ -97,10 +97,10 @@ internal class PointerEvent private constructor() : Event<PointerEvent>() {
9797
}
9898

9999
override fun onDispose() {
100+
eventState = null
100101
pointersEventData = null
101-
val motionEvent = motionEvent
102-
this.motionEvent = null
103102
motionEvent?.recycle()
103+
motionEvent = null
104104

105105
// Either `this` is in the event pool, or motionEvent
106106
// is null. It is in theory not possible for a PointerEvent to
@@ -137,6 +137,7 @@ internal class PointerEvent private constructor() : Event<PointerEvent>() {
137137
val pointerEvent = Arguments.createMap()
138138
val motionEvent = checkNotNull(motionEvent)
139139
val pointerId = motionEvent.getPointerId(index)
140+
val eventState = checkNotNull(eventState)
140141

141142
// https://www.w3.org/TR/pointerevents/#pointerevent-interface
142143
pointerEvent.putDouble("pointerId", pointerId.toDouble())

0 commit comments

Comments
 (0)