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

Commit c5708ef7 authored by Diego Perez's avatar Diego Perez
Browse files

Catch all exceptions in NativeAllocationRegistry free

The NativeAllocationRegistry delegate free calls might run in the
context of the finalizer thread. If a crash happens during the free
call, it might bring down the finalizer thread and the VM.

Bug: http://b.android.com/213927
Change-Id: I8d4b8ab5b8d0532aad46f27d039a943894e021a0
parent 02d091aa
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -52,10 +52,16 @@ public class NativeAllocationRegistry_Delegate {

    @LayoutlibDelegate
    /*package*/ static void applyFreeFunction(long freeFunction, long nativePtr) {
        // This method MIGHT run in the context of the finalizer thread. If the delegate method
        // crashes, it could bring down the VM. That's why we catch all the exceptions and ignore
        // them.
        try {
            NativeAllocationRegistry_Delegate delegate = sManager.getDelegate(freeFunction);
            if (delegate != null) {
                delegate.mFinalizer.free(nativePtr);
            }
        } catch (Throwable ignore) {
        }
    }

    public interface FreeFunction {