title: NewStringUTF() and freeing memory
body: <p>Should I free the allocated string after passing it to <code>NewStringUTF()</code>?</p>
  
  <p>I have some code similar to:</p>
  
  
  
  <pre class="lang-c prettyprint-override"><code>char* test;
  jstring j_test;
  
  test = some_function(); // &lt;- malloc()s the memory
  j_test = (*env)-&gt;NewStringUTF(env, test);
  
  free(test); // &lt;- should this be here?
  </code></pre>
  
  <p>When I free the string after passing it to <code>NewStringUTF()</code>, I get a <code>signal 11 (SIGSEGV), fault addr deadbaad</code> error. If I remove the <code>free()</code> call, the error vanishes. What am I doing wrong?</p>
  
  <p>I see conflicting opinions. Some say I should free it myself, some say the VM frees it, some say the VM doesn't free it and you should do strange voodoo magic to free it. I'm confused.</p>