[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Fix some potential memory leaks in the thread pool code.
commit 3b3b447f75772cc5bbfb48a9e951482dca3c8c0d
Author: cypherpunks <cypherpunks@xxxxxxxxxxxxxx>
Date: Tue Jul 7 10:17:32 2015 +0200
Fix some potential memory leaks in the thread pool code.
---
src/common/compat_pthreads.c | 8 ++++++--
src/common/workqueue.c | 2 ++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/common/compat_pthreads.c b/src/common/compat_pthreads.c
index 487f7e5..b78ab3d 100644
--- a/src/common/compat_pthreads.c
+++ b/src/common/compat_pthreads.c
@@ -64,13 +64,17 @@ spawn_func(void (*func)(void *), void *data)
{
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;
}
diff --git a/src/common/workqueue.c b/src/common/workqueue.c
index ed896d7..3f9a063 100644
--- a/src/common/workqueue.c
+++ b/src/common/workqueue.c
@@ -255,6 +255,7 @@ workerthread_new(void *state, threadpool_t *pool, replyqueue_t *replyqueue)
if (spawn_func(worker_thread_main, thr) < 0) {
log_err(LD_GENERAL, "Can't launch worker thread.");
+ tor_free(thr);
return NULL;
}
@@ -382,6 +383,7 @@ threadpool_start_threads(threadpool_t *pool, int n)
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;
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits