diff options
| author | Robert Carr <racarr@google.com> | 2019-01-07 18:35:30 -0800 |
|---|---|---|
| committer | Robert Carr <racarr@google.com> | 2019-01-07 18:36:36 -0800 |
| commit | eb344c7a357b8a77ec67290eff87513f2e87ccd4 (patch) | |
| tree | 7d8072e6ccd3830f64922f20dfc0df7026a2bb88 /core/java | |
| parent | 30e984ca784e5d3edfe48b827ab0a0ce825adc84 (diff) | |
Fix memory leak in SurfaceControl#copyFrom
Not leaking in practice but if it were used on an already initialized
SurfaceControl Java Wrapper it would leak the old native object by
failing to cal dec strong.
Bug: 111373437
Test: Boots
Change-Id: Ie8f59788630bc2ba05bbdcbbefed4124a4032170
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/view/SurfaceControl.java | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index 0b6beba06555..69f86deb1495 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -360,11 +360,18 @@ public class SurfaceControl implements Parcelable { */ public static final int WINDOW_TYPE_DONT_SCREENSHOT = 441731; + private void assignNativeObject(long nativeObject) { + if (mNativeObject != 0) { + release(); + } + mNativeObject = nativeObject; + } + public void copyFrom(SurfaceControl other) { mName = other.mName; mWidth = other.mWidth; mHeight = other.mHeight; - mNativeObject = nativeCopyFromSurfaceControl(other.mNativeObject); + assignNativeObject(nativeCopyFromSurfaceControl(other.mNativeObject)); } /** @@ -685,12 +692,11 @@ public class SurfaceControl implements Parcelable { mWidth = in.readInt(); mHeight = in.readInt(); - release(); + long object = 0; if (in.readInt() != 0) { - mNativeObject = nativeReadFromParcel(in); - } else { - mNativeObject = 0; + object = nativeReadFromParcel(in); } + assignNativeObject(object); } @Override |
