Skip to content

Commit

Permalink
Always release Java array elements
Browse files Browse the repository at this point in the history
While the [google results] jury appears to be out about whether
hotspot ever returns non-copied elements or not, the memory obtained
from Get*ArrayElements calls must always be released, whether copied
or pinned.
  • Loading branch information
flandr committed Feb 10, 2013
1 parent e72b6b5 commit d691845
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions gsswrapper.i
Expand Up @@ -351,8 +351,8 @@ typedef unsigned int uint32_t; /* for SWIG convienence */
$1 = NULL;
if ($input != NULL) {
/* Get our Java byte array as a char * */
jboolean isCopy;
const char* nativeArray = (char*) (*jenv)->GetByteArrayElements(jenv, $input, &isCopy);
const char* nativeArray =
(char*) (*jenv)->GetByteArrayElements(jenv, $input, NULL);

/* Get the length of our byte array */
$2 = (*jenv)->GetArrayLength(jenv, $input);
Expand All @@ -362,9 +362,7 @@ typedef unsigned int uint32_t; /* for SWIG convienence */
strcpy($1, nativeArray);

/* Release the Java byte[] */
if (isCopy) {
(*jenv)->ReleaseByteArrayElements(jenv, $input, nativeArray, JNI_ABORT);
}
(*jenv)->ReleaseByteArrayElements(jenv, $input, nativeArray, JNI_ABORT);
}
}
%typemap(jni) (char * BYTE, int LENGTH) "jbyteArray"
Expand Down

0 comments on commit d691845

Please sign in to comment.