This is an automated email from the ASF dual-hosted git repository.

schultz pushed a commit to branch 1.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat-native.git


The following commit(s) were added to refs/heads/1.1.x by this push:
     new 33b2bc8c1 Ensure local reference capacity is available for array 
allocations.
33b2bc8c1 is described below

commit 33b2bc8c18621351e2d73a70c24196fb83363ee1
Author: Christopher Schultz <ch...@christopherschultz.net>
AuthorDate: Thu May 16 09:51:45 2024 -0400

    Ensure local reference capacity is available for array allocations.
---
 native/src/jnilib.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/native/src/jnilib.c b/native/src/jnilib.c
index 320cb210e..3886101ba 100644
--- a/native/src/jnilib.c
+++ b/native/src/jnilib.c
@@ -134,6 +134,9 @@ jstring tcn_new_stringn(JNIEnv *env, const char *str, 
size_t l)
 
 jbyteArray tcn_new_arrayb(JNIEnv *env, const unsigned char *data, size_t len)
 {
+    if ((*env)->EnsureLocalCapacity(env, 1) < 0) {
+        return NULL; /* out of memory error */
+    }
     jbyteArray bytes = (*env)->NewByteArray(env, (jsize)len);
     if (bytes != NULL) {
         (*env)->SetByteArrayRegion(env, bytes, 0, (jint)len, (jbyte *)data);
@@ -143,15 +146,22 @@ jbyteArray tcn_new_arrayb(JNIEnv *env, const unsigned 
char *data, size_t len)
 
 jobjectArray tcn_new_arrays(JNIEnv *env, size_t len)
 {
+    if ((*env)->EnsureLocalCapacity(env, 1) < 0) {
+        return NULL; /* out of memory error */
+    }
     return (*env)->NewObjectArray(env, (jsize)len, jString_class, NULL);
 }
 
 jstring tcn_new_string(JNIEnv *env, const char *str)
 {
-    if (!str)
+    if (!str) {
         return NULL;
-    else
+    } else {
+        if ((*env)->EnsureLocalCapacity(env, 1) < 0) {
+            return NULL; /* out of memory error */
+        }
         return (*env)->NewStringUTF(env, str);
+    }
 }
 
 char *tcn_get_string(JNIEnv *env, jstring jstr)


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to