From f56916b26ee4d718e1b7adf5470c8747dac43f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Wr=C3=B3tniak?= Date: Sun, 6 Aug 2017 19:29:45 +0200 Subject: [PATCH] Direct byte buffer global reference added, fixes #434 --- android-gif-drawable/src/main/c/dispose.c | 21 +++++++++------------ android-gif-drawable/src/main/c/gif.c | 1 + android-gif-drawable/src/main/c/gif.h | 1 + 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/android-gif-drawable/src/main/c/dispose.c b/android-gif-drawable/src/main/c/dispose.c index f6eebd0e..ea410434 100644 --- a/android-gif-drawable/src/main/c/dispose.c +++ b/android-gif-drawable/src/main/c/dispose.c @@ -22,19 +22,16 @@ Java_pl_droidsonroids_gif_GifInfoHandle_free(JNIEnv *env, jclass __unused handle (*env)->DeleteGlobalRef(env, streamContainer->buffer); free(streamContainer); - } - else if (info->rewindFunction == fileRewind) { + } else if (info->rewindFunction == fileRewind) { fclose(info->gifFilePtr->UserData); - } - else if (info->rewindFunction == byteArrayRewind) { - ByteArrayContainer *bac = info->gifFilePtr->UserData; - if (bac->buffer != NULL) { - (*env)->DeleteGlobalRef(env, bac->buffer); - } - free(bac); - } - else if (info->rewindFunction == directByteBufferRewind) { - free(info->gifFilePtr->UserData); + } else if (info->rewindFunction == byteArrayRewind) { + ByteArrayContainer *container = info->gifFilePtr->UserData; + (*env)->DeleteGlobalRef(env, container->buffer); + free(container); + } else if (info->rewindFunction == directByteBufferRewind) { + DirectByteBufferContainer *container = info->gifFilePtr->UserData; + (*env)->DeleteGlobalRef(env, container->bufferRef); + free(container); } info->gifFilePtr->UserData = NULL; cleanUp(info); diff --git a/android-gif-drawable/src/main/c/gif.c b/android-gif-drawable/src/main/c/gif.c index e7b3b171..84a5984b 100644 --- a/android-gif-drawable/src/main/c/gif.c +++ b/android-gif-drawable/src/main/c/gif.c @@ -203,6 +203,7 @@ Java_pl_droidsonroids_gif_GifInfoHandle_openDirectByteBuffer(JNIEnv *env, jclass throwException(env, OUT_OF_MEMORY_ERROR, OOME_MESSAGE); return NULL_GIF_INFO; } + container->bufferRef = (*env)->NewGlobalRef(env, buffer); container->bytes = bytes; container->capacity = capacity; container->position = 0; diff --git a/android-gif-drawable/src/main/c/gif.h b/android-gif-drawable/src/main/c/gif.h index d5c90b2d..d8a98a0d 100644 --- a/android-gif-drawable/src/main/c/gif.h +++ b/android-gif-drawable/src/main/c/gif.h @@ -138,6 +138,7 @@ typedef struct { jlong position; jbyte *bytes; jlong capacity; + jobject bufferRef; } DirectByteBufferContainer; typedef struct {