{
pthread_t thread;
tor_pthread_data_t *d;
- if (PREDICT_UNLIKELY(!threads_initialized))
+ if (PREDICT_UNLIKELY(!threads_initialized)) {
tor_threads_init();
+ }
d = tor_malloc(sizeof(tor_pthread_data_t));
d->data = data;
d->func = func;
- if (pthread_create(&thread,&attr_detached,tor_pthread_helper_fn,d))
+ if (pthread_create(&thread, &attr_detached, tor_pthread_helper_fn, d)) {
+ tor_free(d);
return -1;
+ }
+
return 0;
}
if (spawn_func(worker_thread_main, thr) < 0) {
log_err(LD_GENERAL, "Can't launch worker thread.");
+ tor_free(thr);
return NULL;
}
workerthread_t *thr = workerthread_new(state, pool, pool->reply_queue);
if (!thr) {
+ pool->free_thread_state_fn(state);
tor_mutex_release(&pool->lock);
return -1;
}