diff options
| author | Riddle Hsu <riddlehsu@google.com> | 2019-07-04 16:10:08 +0800 |
|---|---|---|
| committer | Ryan Mitchell <rtmitchell@google.com> | 2020-01-17 18:56:15 +0000 |
| commit | 0a8a1e9d40a3cdff06150c43c623fa4c415226b6 (patch) | |
| tree | 7726de86131977aa9f22d0610660fe0ca24cce43 /core/java/android | |
| parent | d0715a9f072b17267b0397642f958a843a1e7582 (diff) | |
Fix potential double destroy of AssetManager
Assume there is a XmlBlock [X] created by a AssetManager [A]
([A] will have mNumRefs = 2). After [A].close is called
(mNumRefs = 1) and then both [X] and [A] are going to be GCed,
if [A].finalize is called first (nativeDestroy), the later
[X].finalize will invoke [A].xmlBlockGone that triggers the
second nativeDestroy of [A] and leads to crash.
By clearing the mObject in AssetManager.finalize, the
decRefsLocked from other paths won't call nativeDestroy again.
Bug: 136721562
Bug: 144028297
Test: atest AssetManagerTest
Test: Build and install CorePerfTests
adb shell am instrument -w -r --no-hidden-api-checks -e class \
android.app.ResourcesPerfTest#getLayoutAndTravese,android.graphics.perftests.RenderNodePerfTest \
com.android.perftests.core/androidx.test.runner.AndroidJUnitRunner
Change-Id: Ia938502d2443f5a6de6a3cabdb7ce1d41d3ff6d1
Merged-In: Ia938502d2443f5a6de6a3cabdb7ce1d41d3ff6d1
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/content/res/AssetManager.java | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/core/java/android/content/res/AssetManager.java b/core/java/android/content/res/AssetManager.java index 289534273d13..4ddaa9b4cdf8 100644 --- a/core/java/android/content/res/AssetManager.java +++ b/core/java/android/content/res/AssetManager.java @@ -1050,8 +1050,11 @@ public final class AssetManager implements AutoCloseable { } } - if (mObject != 0) { - nativeDestroy(mObject); + synchronized (this) { + if (mObject != 0) { + nativeDestroy(mObject); + mObject = 0; + } } } |
