Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4566b797 authored by Phil Dubach's avatar Phil Dubach
Browse files

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.
parent 3f4263fa
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -1404,8 +1404,12 @@ public class Canvas {
    
    protected void finalize() throws Throwable {
        super.finalize();
        // If the constructor threw an exception before setting mNativeCanvas, the native finalizer
        // must not be invoked.
        if (mNativeCanvas != 0) {
            finalizer(mNativeCanvas);
        }
    }

    /**
     * Free up as much memory as possible from private caches (e.g. fonts,