[libguestfs PATCH] java: free JNI local refs in the event callback
java_callback allocates a jstring and a jlongArray on every event. The callback runs on the Java thread already inside a JNI native method, so those local refs stay in the outer frame until that method returns. A progress or appliance-log handler can fire often enough in one call to overflow the JNI local reference table. Push a local frame around the callback and pop it after CallVoidMethod returns. Fixes: https://github.com/libguestfs/libguestfs/issues/403 Signed-off-by: qiuyucheng <2847117296@qq.com> --- java/handle.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/java/handle.c b/java/handle.c index 629dfd95e..501c09e7f 100644 --- a/java/handle.c +++ b/java/handle.c @@ -155,6 +155,15 @@ java_callback (guestfs_h *g, } } + /* Events run on the Java thread already inside a JNI call, so + * local refs created here stay live until that outer call returns. + */ + if ((*env)->PushLocalFrame (env, 16) < 0) { + (*env)->ExceptionDescribe (env); + (*env)->ExceptionClear (env); + return; + } + /* Convert the buffer and array to Java objects. */ jbuf = (*env)->NewStringUTF (env, buf); // XXX size @@ -175,6 +184,8 @@ java_callback (guestfs_h *g, (*env)->ExceptionDescribe (env); (*env)->ExceptionClear (env); } + + (*env)->PopLocalFrame (env, NULL); } JNIEXPORT jint JNICALL -- 2.33.0
participants (1)
-
qiuyucheng