@@ -133,19 +133,19 @@ create_callback(JNIEnv* env, jobject obj, jobject method,
133133 }
134134 argc = (* env )-> GetArrayLength (env , arg_classes );
135135
136- cb = (callback * )malloc ( sizeof (callback ));
136+ cb = (callback * )calloc ( 1 , sizeof (callback ));
137137 cb -> closure = ffi_closure_alloc (sizeof (ffi_closure ), & cb -> x_closure );
138138 cb -> saved_x_closure = cb -> x_closure ;
139139 cb -> object = (* env )-> NewWeakGlobalRef (env , obj );
140140 cb -> methodID = (* env )-> FromReflectedMethod (env , method );
141141
142142 cb -> vm = vm ;
143- cb -> arg_types = (ffi_type * * )malloc ( sizeof (ffi_type * ) * argc );
144- cb -> java_arg_types = (ffi_type * * )malloc ( sizeof ( ffi_type * ) * ( argc + 3 ));
145- cb -> arg_jtypes = (char * )malloc ( sizeof (char ) * argc );
146- cb -> conversion_flags = (int * )malloc ( sizeof (int ) * argc );
143+ cb -> arg_types = (ffi_type * * )calloc ( argc , sizeof (ffi_type * ));
144+ cb -> java_arg_types = (ffi_type * * )calloc ( argc + 3 , sizeof ( ffi_type * ));
145+ cb -> arg_jtypes = (char * )calloc ( argc , sizeof (char ));
146+ cb -> conversion_flags = (int * )calloc ( argc , sizeof (int ));
147147 cb -> rflag = CVT_DEFAULT ;
148- cb -> arg_classes = (jobject * )malloc ( sizeof (jobject ) * argc );
148+ cb -> arg_classes = (jobject * )calloc ( argc , sizeof (jobject ));
149149
150150 cb -> direct = direct ;
151151 cb -> java_arg_types [0 ] = cb -> java_arg_types [1 ] = cb -> java_arg_types [2 ] = & ffi_type_pointer ;
@@ -163,6 +163,9 @@ create_callback(JNIEnv* env, jobject obj, jobject method,
163163 }
164164
165165 jtype = get_java_type (env , cls );
166+ if ((* env )-> ExceptionCheck (env )) {
167+ goto failure_cleanup ;
168+ }
166169 if (jtype == -1 ) {
167170 snprintf (msg , sizeof (msg ), "Unsupported callback argument at index %d" , i );
168171 throw_type = EIllegalArgument ;
@@ -179,7 +182,13 @@ create_callback(JNIEnv* env, jobject obj, jobject method,
179182 || cb -> conversion_flags [i ] == CVT_INTEGER_TYPE ) {
180183 jclass ncls ;
181184 ncls = getNativeType (env , cls );
185+ if ((* env )-> ExceptionCheck (env )) {
186+ goto failure_cleanup ;
187+ }
182188 jtype = get_java_type (env , ncls );
189+ if ((* env )-> ExceptionCheck (env )) {
190+ goto failure_cleanup ;
191+ }
183192 if (jtype == -1 ) {
184193 snprintf (msg , sizeof (msg ), "Unsupported NativeMapped callback argument native type at argument %d" , i );
185194 throw_type = EIllegalArgument ;
@@ -560,7 +569,7 @@ static TLS_KEY_T tls_thread_data_key;
560569static thread_storage * get_thread_storage (JNIEnv * env ) {
561570 thread_storage * tls = (thread_storage * )TLS_GET (tls_thread_data_key );
562571 if (tls == NULL ) {
563- tls = (thread_storage * )malloc ( sizeof (thread_storage ));
572+ tls = (thread_storage * )calloc ( 1 , sizeof (thread_storage ));
564573 if (!tls ) {
565574 throwByName (env , EOutOfMemory , "JNA: Can't allocate thread storage" );
566575 }
0 commit comments