Hi,
I'm experimenting with JNI and implemented a simple function. It works fine without the ReleaseByteArrayElements call but when adding it I get following error:
*** glibc detected *** /opt/jdk1.6.0_13/bin/java: munmap_chunk(): invalid pointer: 0xb80d6d70 ***
I guess something have to be wrong but I have no idea what it could be.
Any ideas?
Thanks.
I'm experimenting with JNI and implemented a simple function. It works fine without the ReleaseByteArrayElements call but when adding it I get following error:
*** glibc detected *** /opt/jdk1.6.0_13/bin/java: munmap_chunk(): invalid pointer: 0xb80d6d70 ***
I guess something have to be wrong but I have no idea what it could be.
Any ideas?
Thanks.
Code:
JNIEXPORT jstring JNICALL Java_Main_getImageString
(JNIEnv *env, jobject) {
FILE *file = fopen(image, "rb");
// Put file in buffer
int fileLen;
fseek(file, 0, SEEK_END);
fileLen = ftell(file);
fseek(file, 0, SEEK_SET);
char buffer[fileLen];
fread(buffer, fileLen, 1, file);
fclose(file);
// Do the JNI stuff
jbyteArray ret = env->NewByteArray(fileLen);
env->SetByteArrayRegion(ret, 0, fileLen, (signed char*) buffer);
env->ReleaseByteArrayElements(ret, buffer, 0);
return ret;
}