@@ -226,6 +226,7 @@ runner(void *vp)
226
226
goto fail ;
227
227
}
228
228
fail :
229
+ instance_destroy (inst );
229
230
toywasm_mutex_lock (& wasi -> lock );
230
231
idalloc_free (& wasi -> tids , tid );
231
232
assert (wasi -> nrunners > 0 );
@@ -235,7 +236,6 @@ runner(void *vp)
235
236
assert (ret == 0 );
236
237
}
237
238
toywasm_mutex_unlock (& wasi -> lock );
238
- instance_destroy (inst );
239
239
return NULL ;
240
240
}
241
241
@@ -248,6 +248,7 @@ wasi_thread_spawn(struct exec_context *ctx, struct host_instance *hi,
248
248
struct wasi_threads_instance * wasi = (void * )hi ;
249
249
HOST_FUNC_CONVERT_PARAMS (ft , params );
250
250
uint32_t user_arg = HOST_FUNC_PARAM (ft , params , 0 , i32 );
251
+ struct instance * inst = NULL ;
251
252
struct thread_arg * arg = NULL ;
252
253
uint32_t tid ;
253
254
int ret ;
@@ -272,7 +273,6 @@ wasi_thread_spawn(struct exec_context *ctx, struct host_instance *hi,
272
273
goto fail ;
273
274
}
274
275
275
- struct instance * inst ;
276
276
struct report report ;
277
277
report_init (& report );
278
278
ret = instance_create (wasi -> module , & inst , ctx -> instance ,
@@ -308,6 +308,7 @@ wasi_thread_spawn(struct exec_context *ctx, struct host_instance *hi,
308
308
xlog_trace ("%s: pthread_create failed with %d" , __func__ , ret );
309
309
goto fail ;
310
310
}
311
+ inst = NULL ;
311
312
arg = NULL ;
312
313
313
314
ret = pthread_detach (t );
@@ -323,6 +324,9 @@ wasi_thread_spawn(struct exec_context *ctx, struct host_instance *hi,
323
324
toywasm_mutex_unlock (& wasi -> lock );
324
325
325
326
fail :
327
+ if (inst != NULL ) {
328
+ instance_destroy (inst );
329
+ }
326
330
free (arg );
327
331
int32_t result ;
328
332
if (ret != 0 ) {
0 commit comments