tags:

views:

3

answers:

0

I have trouble with the jvm.dll when after the returning from the function below I get the error message _HEAP[test_heap.exe]: Invalid Address specified to RtlValidateHeap_

At the moment I dynamically load the JNI_CreateJavaVM method only, everything goes well until I go past the final return statement of the function test_heap below:

int test_heap(wchar_t* javalib, char* classPath)
{
    JNIEnv *env;
    JavaVM *jvm;

    JavaVMInitArgs vm_args;
    JavaVMOption options[3];
    options[0].optionString = classPath;
    options[1].optionString = "-verbose:jni";
    vm_args.version = JNI_VERSION_1_6;
    vm_args.nOptions = 2;
    vm_args.options = options; //NULL;
    vm_args.ignoreUnrecognized = JNI_TRUE;

    /* Create the Java VM */
    HMODULE hJvm = LoadLibrary(javalib);

    if (!hJvm)
        return -1;

    CreateJavaVM_t *pfnCreateJavaVM = (CreateJavaVM_t *)GetProcAddress(hJvm, "JNI_CreateJavaVM");
    if(pfnCreateJavaVM == NULL)
        return -2;

    int rc = pfnCreateJavaVM(&jvm, (void**)&env, &vm_args);
    if(rc != 0)
        return -3;

    jvm->DestroyJavaVM();
    FreeLibrary(hJvm);

    return 0;
}