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';
r = (*env)->NewStringUTF(env, emptystring);
free(emptystring);
emptystring = NULL;
return r;
}
Yes. (Just so this doesn't look unanswered.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With