diff options
author | Phil Dubach <phillipd@google.com> | 2009-06-17 15:27:42 -0700 |
---|---|---|
committer | Phil Dubach <phillipd@google.com> | 2009-06-17 18:26:32 -0700 |
commit | 4566b79736f236c0f605c57130d1fa954f4642d6 (patch) | |
tree | 38640c9b8dc0cbdc958350d6023bd7df64ec90d0 | |
parent | 3f4263fac6bcc68b3c7fff8e6ac9ad2d97b2ad4c (diff) | |
download | frameworks_base-4566b79736f236c0f605c57130d1fa954f4642d6.zip frameworks_base-4566b79736f236c0f605c57130d1fa954f4642d6.tar.gz frameworks_base-4566b79736f236c0f605c57130d1fa954f4642d6.tar.bz2 |
Fix Canvas.finalize() for the case where the constructor throws an exception
before the native canvas instance was created.
If the canvas constructors throw an exception (because the bitmap passed in is
immutable or already recycled), the constructor terminates early without
allocating the native canvas instance. For the most part, that's okay, since
the Canvas instance will never be returned to the application. However, the GC
will still call finalize() on the half-initialized Canvas.
The native methods for Canvas all assume that the canvas pointer passed down is
not null.
-rw-r--r-- | graphics/java/android/graphics/Canvas.java | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java index 06d53e3..4498e1a 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -1404,7 +1404,11 @@ public class Canvas { protected void finalize() throws Throwable { super.finalize(); - finalizer(mNativeCanvas); + // If the constructor threw an exception before setting mNativeCanvas, the native finalizer + // must not be invoked. + if (mNativeCanvas != 0) { + finalizer(mNativeCanvas); + } } /** |