Refactor native MotionEvent_obtain to avoid possible memory leak
android_view_MotionEvent_setNativePtr doesn't check if the supplied java MotionEvent already holds a native pointer before overwriting it. This can potentially cause native MotionEvent object to be leaked. Currently this is only used in android_view_MotionEvent_obtainFromNative without checking for existing native pointer in corresponding java object. This can potantially leak native heap in android.view.MotionPredictor if the obtained java MotionEvent was recycled and holding a native MotionEvent object. In this CL we change it to first check for existing native object and copy the data instead avoiding allocating new native MotionEvent. This will also allow us to safely use it in MotionEvent_obtainAsCopy method. Test: atest MotionEventTest Bug: 328562482 Bug: 324375527 Change-Id: Iff6b4211ea23a940dcfe3acddd4464ccdc0799d1
Loading
Please register or sign in to comment