Skip to content

Commit

Permalink
Direct byte buffer global reference added, fixes #434
Browse files Browse the repository at this point in the history
  • Loading branch information
koral-- committed Aug 6, 2017
1 parent 876b093 commit f56916b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
21 changes: 9 additions & 12 deletions android-gif-drawable/src/main/c/dispose.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions android-gif-drawable/src/main/c/gif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions android-gif-drawable/src/main/c/gif.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ typedef struct {
jlong position;
jbyte *bytes;
jlong capacity;
jobject bufferRef;
} DirectByteBufferContainer;

typedef struct {
Expand Down

0 comments on commit f56916b

Please sign in to comment.