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

Commit 08d7778f authored by Kimiyoshi Kusaka's avatar Kimiyoshi Kusaka
Browse files

Fix memory leak of SkMovie class

Movie class doesn't have finalize method.
So memory leak of SkMovie class of native Skia occurs when Movie class is released.
I add finalize method to Movie class (Movie.java) and jni destructor method to SkMovie class (Movie.cpp).

Change-Id: I4dae9dd95f128cbfade50bef978b219ba99321dd
parent 2e383bc6
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -115,6 +115,10 @@ static jobject movie_decodeByteArray(JNIEnv* env, jobject clazz,
    return create_jmovie(env, moov);
}

static void movie_destructor(JNIEnv* env, jobject, SkMovie* movie) {
    delete movie;
}

//////////////////////////////////////////////////////////////////////////////////////////////

#include <android_runtime/AndroidRuntime.h>
@@ -129,6 +133,7 @@ static JNINativeMethod gMethods[] = {
                            (void*)movie_draw  },
    { "decodeStream", "(Ljava/io/InputStream;)Landroid/graphics/Movie;",
                            (void*)movie_decodeStream },
    { "nativeDestructor","(I)V", (void*)movie_destructor },
    { "decodeByteArray", "([BII)Landroid/graphics/Movie;",
                            (void*)movie_decodeByteArray },
};
+11 −0
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@ public class Movie {
    public static native Movie decodeByteArray(byte[] data, int offset,
                                               int length);

    private static native void nativeDestructor(int nativeMovie);

    public static Movie decodeFile(String pathName) {
        InputStream is;
        try {
@@ -57,6 +59,15 @@ public class Movie {
        return decodeTempStream(is);
    }

    @Override
    protected void finalize() throws Throwable {
        try {
            nativeDestructor(mNativeMovie);
        } finally {
            super.finalize();
        }
    }

    private static Movie decodeTempStream(InputStream is) {
        Movie moov = null;
        try {