title: (*vm)->GetEnv segfaults only on HTC devices
body: <p>Im currently working on a bigger project with multiple threads in the native environment. Therefore I need a call to (*vm)->GetEnv to receive the currently active JNIEnv for the native thread. The threads are attached on creation but I added a fail-over in the method which calls GetEnv:</p>
  
  <pre><code>void get_jni_env(void **e) {
      JNIEnv *env = malloc(sizeof(JNIEnv *));
  
      if((*vm)-&gt;GetEnv(vm, (void **)&amp;env, JNI_VERSION_1_4) != JNI_OK) {
          __android_log_write(ANDROID_LOG_ERROR, "Call to GetEnv from a unattached native thread. Trying to attach thread.");
          if((*vm)-&gt;AttachCurrentThread(vm, &amp;env, NULL) != JNI_OK) {
              __android_log_write(ANDROID_LOG_ERROR, "Failed to receive any jni environment. Crashing soon");
          }
      }
  
      *e = env;
  }
  </code></pre>
  
  <p>When stepped through you see that the call to (*vm)->GetEnv segfaults:</p>
  
  <pre><code>jni_get_long (ctx=0x40525080, key=0x804215e0 "hm") at jni/jni.c:50
  50      GET_JNI_ENV(&amp;env);
  (gdb) s
  get_jni_env (e=0xbec603e8) at jni/../../../../core/android/util.c:159
  159     if((*vm)-&gt;GetEnv(vm, (void **)&amp;env, JNI_VERSION_1_4) != JNI_OK) {
  (gdb) n
  156 void get_jni_env(void **e) {
  (gdb) 
  157     JNIEnv *env = malloc(sizeof(JNIEnv *));
  (gdb) 
  159     if((*vm)-&gt;GetEnv(vm, (void **)&amp;env, JNI_VERSION_1_4) != JNI_OK) {
  (gdb) 
  
  Program received signal SIGSEGV, Segmentation fault.
  0xaca43510 in ?? ()  ← this is somewhere on the heap
  </code></pre>
  
  <p>The same code works perfectly fine on Samsung and Sony Ericsson devices as well as in the emulator. I'm somewhat out of ideas for this particular error. I also tested an HTC device with CyanogenMod 7.1 which should be fairly similar to the AOSP android and even there it crashes at the same point.</p>