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

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


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

commit e49f0fe5c26612df01c636e7019cd70d78948976
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 342df3b9c..836502c52 100644
--- a/native/src/jnilib.c
+++ b/native/src/jnilib.c
@@ -133,6 +133,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);
@@ -142,15 +145,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