Recycle MotionEvents for ACTION_OUTSIDE in WindowManagerService

Change-Id: I648e5ad780cad285f190e06cfff1780c6dad0117
diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java
index 6966400..9cc73aa 100644
--- a/services/java/com/android/server/WindowManagerService.java
+++ b/services/java/com/android/server/WindowManagerService.java
@@ -5185,19 +5185,24 @@
                     WindowState out = mKeyWaiter.mOutsideTouchTargets;
                     if (out != null) {
                         MotionEvent oev = MotionEvent.obtain(ev);
-                        oev.setAction(MotionEvent.ACTION_OUTSIDE);
-                        do {
-                            final Rect frame = out.mFrame;
-                            oev.offsetLocation(-(float)frame.left, -(float)frame.top);
-                            try {
-                                out.mClient.dispatchPointer(oev, eventTime, false);
-                            } catch (android.os.RemoteException e) {
-                                Slog.i(TAG, "WINDOW DIED during outside motion dispatch: " + out);
-                            }
-                            oev.offsetLocation((float)frame.left, (float)frame.top);
-                            out = out.mNextOutsideTouch;
-                        } while (out != null);
-                        mKeyWaiter.mOutsideTouchTargets = null;
+                        try {
+                            oev.setAction(MotionEvent.ACTION_OUTSIDE);
+                            do {
+                                final Rect frame = out.mFrame;
+                                oev.offsetLocation(-(float)frame.left, -(float)frame.top);
+                                try {
+                                    out.mClient.dispatchPointer(oev, eventTime, false);
+                                } catch (android.os.RemoteException e) {
+                                    Slog.i(TAG,
+                                            "WINDOW DIED during outside motion dispatch: " + out);
+                                }
+                                oev.offsetLocation((float)frame.left, (float)frame.top);
+                                out = out.mNextOutsideTouch;
+                            } while (out != null);
+                            mKeyWaiter.mOutsideTouchTargets = null;
+                        } finally {
+                            oev.recycle();
+                        }
                     }
                 }