mobile/bind: fix JNI local reference table overflow

The existing implementation has  memory leaks on two local variables
that are not deleted after use. Android app will crash after this issue.

add UnitTest for this issue.

Fixes golang/go#14346

Change-Id: Ic233d15556ac97b35e00e13279a572c48a03049f
Reviewed-on: https://go-review.googlesource.com/19532
Reviewed-by: Elias Naur <elias.naur@gmail.com>
This commit is contained in:
ttyh061
2016-02-17 14:34:31 +00:00
committed by Elias Naur
parent 1fb745cd55
commit 5a8964bd48
3 changed files with 24 additions and 2 deletions
+12 -2
View File
@@ -4,10 +4,9 @@
package go;
import android.util.Log;
import android.test.suitebuilder.annotation.Suppress;
import android.test.AndroidTestCase;
import android.test.MoreAsserts;
import java.util.Arrays;
import java.util.Random;
@@ -386,6 +385,17 @@ public class SeqTest extends AndroidTestCase {
assertEquals("want back the error message we set", want, got);
}
//test if we have JNI local reference table overflow error
public void testLocalReferenceOverflow() {
Testpkg.CallWithCallback(new Testpkg.GoCallback.Stub() {
@Override
public void VarUpdate() {
//do nothing
}
});
}
public void testNullReferences() {
assertTrue(Testpkg.CallWithNull(null, new Testpkg.NullTest.Stub() {
public Testpkg.NullTest Null() {
+2
View File
@@ -262,12 +262,14 @@ void recv(int32_t ref, int code, uint8_t *in_ptr, size_t in_len, uint8_t **out_p
memcpy(mem_write(env, in, in_len, 1), in_ptr, in_len);
in_mem->off = 0;
out = (*env)->CallStaticObjectMethod(env, seq_clazz, seq_recv, in, code, ref);
(*env)->DeleteLocalRef(env, in);
if (out == NULL) {
describe_exception(env);
LOG_FATAL("failed to invoke Seq.recv");
return;
}
out_mem = mem_get(env, out);
(*env)->DeleteLocalRef(env, out);
if (out_mem == NULL) {
LOG_FATAL("recv on NULL out_mem");
return;
+10
View File
@@ -220,6 +220,16 @@ func ReadAsset() string {
return string(b)
}
type GoCallback interface {
VarUpdate()
}
func CallWithCallback(gcb GoCallback) {
for i := 0; i < 1000; i++ {
gcb.VarUpdate()
}
}
type NullTest interface {
Null() NullTest
}