ReleaseByteArrayElements fails

Joined
Mar 27, 2009
Messages
1
Reaction score
0
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.

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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top