From 007afe7ac82dbee5478b898092426b29fe143a60 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 9 Jun 2014 12:02:03 +1000 Subject: [PATCH] Cancel and join proxy send and receive threads on shutdown to avoid deref after removing their memory --- src/generator.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/generator.c b/src/generator.c index f1478b8c..998cd7b1 100644 --- a/src/generator.c +++ b/src/generator.c @@ -961,9 +961,6 @@ static void *proxy_recv(void *arg) ckpool_t *ckp = proxi->ckp; rename_proc("proxyrecv"); - /* We don't wait for them to pthread_join in case it takes a while, so - * we detach the threads instead to clean up themselves */ - pthread_detach(pthread_self()); while (42) { notify_instance_t *ni, *tmp; @@ -1043,7 +1040,6 @@ static void *proxy_send(void *arg) connsock_t *cs = proxi->cs; rename_proc("proxysend"); - pthread_detach(pthread_self()); while (42) { notify_instance_t *ni; @@ -1312,6 +1308,10 @@ static int proxy_mode(ckpool_t *ckp, proc_instance_t *pi) free(proxi->enonce1); free(proxi->enonce1bin); free(proxi->sessionid); + pthread_cancel(proxi->pth_psend); + pthread_cancel(proxi->pth_precv); + join_pthread(proxi->pth_psend); + join_pthread(proxi->pth_precv); dealloc(si->data); dealloc(si->url); dealloc(si->auth);