Exit cleanly if we abort before various threads are set up or if they no longer exist.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
diff --git a/main.c b/main.c
index 1074480..166b39c 100644
--- a/main.c
+++ b/main.c
@@ -2255,25 +2255,28 @@ void kill_work(void)
/* Kill the watchdog thread */
thr = &thr_info[watchdog_thr_id];
- if (thr->pth)
+ if (thr && thr->pth)
pthread_cancel(*thr->pth);
/* Stop the mining threads*/
for (i = 0; i < mining_threads; i++) {
thr = &thr_info[i];
+ if (!thr)
+ continue;
if (!thr->pth)
continue;
- tq_freeze(thr->q);
+ if (thr->q)
+ tq_freeze(thr->q);
/* No need to check if this succeeds or not */
pthread_cancel(*thr->pth);
}
/* Stop the others */
thr = &thr_info[stage_thr_id];
- if (thr->pth)
+ if (thr && thr->pth)
pthread_cancel(*thr->pth);
thr = &thr_info[longpoll_thr_id];
- if (thr->pth)
+ if (thr && thr->pth)
pthread_cancel(*thr->pth);
wc = calloc(1, sizeof(*wc));
@@ -2289,14 +2292,16 @@ void kill_work(void)
if (opt_debug)
applog(LOG_DEBUG, "Pushing die request to work thread");
- if (unlikely(!tq_push(thr_info[work_thr_id].q, wc))) {
- applog(LOG_ERR, "Failed to tq_push work in kill_work");
- exit (1);
- }
-
thr = &thr_info[work_thr_id];
- if (thr->pth)
- pthread_cancel(*thr->pth);
+ if (thr) {
+ if (unlikely(!tq_push(thr->q, wc))) {
+ applog(LOG_ERR, "Failed to tq_push work in kill_work");
+ exit (1);
+ }
+
+ if (thr->pth)
+ pthread_cancel(*thr->pth);
+ }
}
void quit(int status, const char *format, ...);