From 40e361cb78773dd8682f665196db91e8be4666d1 Mon Sep 17 00:00:00 2001 From: chaviw Date: Tue, 10 May 2022 12:40:58 -0500 Subject: [PATCH] Lock in Surface#destroy Previously, destroy just directly called release, which was already locked. Now, destroy invokes some functions in native. This means if another thread is calling release during the destroy call, it could cause crashes. Test: Hard to repro bug Bug: 223412469 Change-Id: Ie6415f505bbc86505e3fe3ea2a0bea96a3e78ad3 --- core/java/android/view/Surface.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java index e5ec260907df6..691452f51ee8b 100644 --- a/core/java/android/view/Surface.java +++ b/core/java/android/view/Surface.java @@ -341,10 +341,12 @@ public class Surface implements Parcelable { */ @UnsupportedAppUsage public void destroy() { - if (mNativeObject != 0) { - nativeDestroy(mNativeObject); + synchronized (mLock) { + if (mNativeObject != 0) { + nativeDestroy(mNativeObject); + } + release(); } - release(); } /**