@@ -133,19 +133,19 @@ create_callback(JNIEnv* env, jobject obj, jobject method,
133
133
}
134
134
argc = (* env )-> GetArrayLength (env , arg_classes );
135
135
136
- cb = (callback * )malloc ( sizeof (callback ));
136
+ cb = (callback * )calloc ( 1 , sizeof (callback ));
137
137
cb -> closure = ffi_closure_alloc (sizeof (ffi_closure ), & cb -> x_closure );
138
138
cb -> saved_x_closure = cb -> x_closure ;
139
139
cb -> object = (* env )-> NewWeakGlobalRef (env , obj );
140
140
cb -> methodID = (* env )-> FromReflectedMethod (env , method );
141
141
142
142
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 ));
147
147
cb -> rflag = CVT_DEFAULT ;
148
- cb -> arg_classes = (jobject * )malloc ( sizeof (jobject ) * argc );
148
+ cb -> arg_classes = (jobject * )calloc ( argc , sizeof (jobject ));
149
149
150
150
cb -> direct = direct ;
151
151
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,
163
163
}
164
164
165
165
jtype = get_java_type (env , cls );
166
+ if ((* env )-> ExceptionCheck (env )) {
167
+ goto failure_cleanup ;
168
+ }
166
169
if (jtype == -1 ) {
167
170
snprintf (msg , sizeof (msg ), "Unsupported callback argument at index %d" , i );
168
171
throw_type = EIllegalArgument ;
@@ -179,7 +182,13 @@ create_callback(JNIEnv* env, jobject obj, jobject method,
179
182
|| cb -> conversion_flags [i ] == CVT_INTEGER_TYPE ) {
180
183
jclass ncls ;
181
184
ncls = getNativeType (env , cls );
185
+ if ((* env )-> ExceptionCheck (env )) {
186
+ goto failure_cleanup ;
187
+ }
182
188
jtype = get_java_type (env , ncls );
189
+ if ((* env )-> ExceptionCheck (env )) {
190
+ goto failure_cleanup ;
191
+ }
183
192
if (jtype == -1 ) {
184
193
snprintf (msg , sizeof (msg ), "Unsupported NativeMapped callback argument native type at argument %d" , i );
185
194
throw_type = EIllegalArgument ;
@@ -560,7 +569,7 @@ static TLS_KEY_T tls_thread_data_key;
560
569
static thread_storage * get_thread_storage (JNIEnv * env ) {
561
570
thread_storage * tls = (thread_storage * )TLS_GET (tls_thread_data_key );
562
571
if (tls == NULL ) {
563
- tls = (thread_storage * )malloc ( sizeof (thread_storage ));
572
+ tls = (thread_storage * )calloc ( 1 , sizeof (thread_storage ));
564
573
if (!tls ) {
565
574
throwByName (env , EOutOfMemory , "JNA: Can't allocate thread storage" );
566
575
}
0 commit comments