Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ReleaseByteArrayElements fails

843829Mar 29 2009 — edited Mar 29 2009
Hi,

The call to ReleaseByteArrayElements throws following error: *** glibc detected *** /opt/jdk1.6.0_13/bin/java: munmap_chunk(): invalid pointer: 0xb80d6d70 ***

Without the call the code works fine.

Any ideas?
Thanks.
JNIEXPORT jstring JNICALL Java_Main_getImage
(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, (signed char*) buffer, 0);

    return ret;
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 26 2009
Added on Mar 29 2009
2 comments
342 views