From eff09c66a4214cb9407a1f5906347a1c2143f167 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Tue, 8 Aug 2017 12:54:28 -0400 Subject: [PATCH] lib: fix still reachable linked list in thread.c Signed-off-by: Quentin Young --- lib/thread.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/thread.c b/lib/thread.c index fd36eaf3885c..4a5c61d036f6 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -340,9 +340,6 @@ static void cancelreq_del(void *cr) /* initializer, only ever called once */ static void initializer() { - if (!masters) - masters = list_new(); - pthread_key_create(&thread_current, NULL); } @@ -415,9 +412,12 @@ struct thread_master *thread_master_create(const char *name) rv->handler.copy = XCALLOC(MTYPE_THREAD_MASTER, sizeof(struct pollfd) * rv->handler.pfdsize); - /* add to list */ + /* add to list of threadmasters */ pthread_mutex_lock(&masters_mtx); { + if (!masters) + masters = list_new(); + listnode_add(masters, rv); } pthread_mutex_unlock(&masters_mtx); @@ -551,6 +551,10 @@ void thread_master_free(struct thread_master *m) pthread_mutex_lock(&masters_mtx); { listnode_delete(masters, m); + if (masters->count == 0) { + list_free (masters); + masters = NULL; + } } pthread_mutex_unlock(&masters_mtx);