From a7da8f84caabb975ac0e21ca3c0816bca81413e5 Mon Sep 17 00:00:00 2001
From: Mark Andrews <marka@isc.org>
Date: Wed, 19 Aug 2020 18:45:38 +1000
Subject: [PATCH] isc_ratelimiter needs to hold a reference to its task

to prevent the task subsystem shutting down before the
ratelimiter is freed.

(cherry picked from commit b8e4b6d30325168bee19e1f05e286c5d3592c4ff)
Conflict: NA
Reference: https://gitlab.isc.org/isc-projects/bind9/-/commit/a7da8f84caabb975ac0e21ca3c0816bca81413e5
---
 lib/isc/ratelimiter.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/isc/ratelimiter.c b/lib/isc/ratelimiter.c
index 3fd211f633..1fefe9b25a 100644
--- a/lib/isc/ratelimiter.c
+++ b/lib/isc/ratelimiter.c
@@ -252,11 +252,14 @@ isc_ratelimiter_shutdown(isc_ratelimiter_t *rl) {
 	(void)isc_timer_reset(rl->timer, isc_timertype_inactive,
 			      NULL, NULL, false);
 	while ((ev = ISC_LIST_HEAD(rl->pending)) != NULL) {
+		task = ev->ev_sender;
 		ISC_LIST_UNLINK(rl->pending, ev, ev_ratelink);
 		ev->ev_attributes |= ISC_EVENTATTR_CANCELED;
 		task = ev->ev_sender;
 		isc_task_send(task, &ev);
 	}
+	task = NULL;
+	isc_task_attach(rl->task, &task);
 	isc_timer_detach(&rl->timer);
 
 	/*
@@ -276,6 +279,7 @@ ratelimiter_shutdowncomplete(isc_task_t *task, isc_event_t *event) {
 	UNUSED(task);
 
 	isc_ratelimiter_detach(&rl);
+	isc_task_detach(&task);
 }
 
 static void
-- 
2.23.0

