tags:

views:

582

answers:

1

I think yes, but the top 12 examples I found all do something not illustrative like

JNIEXPORT jstring JCALL Java_com_foo_dumbImpl(JNIEnv* env, jobject thisObj)
{
  return (*env)->NewStringUTF(env, "constant string"); 
}

so for posterity I will ask: this is bad, yes?

JNIEXPORT jstring JCALL Java_com_foo_dumbImpl(JNIEnv* env, jobject thisObj)
{
  char *leak = malloc(1024);
  leak[0] = '\0';
  return (*env)->NewStringUTF(env, leak); 
}

...and should be:

JNIEXPORT jstring JCALL Java_com_foo_dumbImpl(JNIEnv* env, jobject thisObj)
{
  char *emptystring = NULL;
  jstring r = NULL;
  emptystring = malloc(1024);
  emptystring[0] = '\0';
  jstring = (*env)->NewStringUTF(env, emptystring); 
  free(emptystring); emptt
  emptystring = NULL;
  return  r;
}
+1  A: 

Yes. (Just so this doesn't look unanswered.)

dsimms