]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix small problems in the isc_ratelimiter
authorOndřej Surý <ondrej@isc.org>
Thu, 29 Sep 2022 16:06:05 +0000 (18:06 +0200)
committerOndřej Surý <ondrej@isc.org>
Fri, 30 Sep 2022 07:50:17 +0000 (09:50 +0200)
lib/isc/ratelimiter.c

index 8fe422ec730d58b7349f8a16514d2a3c6279c6f9..f4ebcb22cf227bc69873d8fbc0688dcd33b8206c 100644 (file)
@@ -57,10 +57,13 @@ ratelimiter_tick(void *arg);
 isc_result_t
 isc_ratelimiter_create(isc_loop_t *loop, isc_ratelimiter_t **ratelimiterp) {
        isc_ratelimiter_t *rl = NULL;
-       isc_mem_t *mctx = isc_loop_getmctx(loop);
+       isc_mem_t *mctx;
 
+       INSIST(loop != NULL);
        INSIST(ratelimiterp != NULL && *ratelimiterp == NULL);
 
+       mctx = isc_loop_getmctx(loop);
+
        rl = isc_mem_get(mctx, sizeof(*rl));
        *rl = (isc_ratelimiter_t){
                .pertic = 1,
@@ -237,14 +240,16 @@ isc_ratelimiter_shutdown(isc_ratelimiter_t *rl) {
        REQUIRE(VALID_RATELIMITER(rl));
 
        LOCK(&rl->lock);
-       rl->state = isc_ratelimiter_shuttingdown;
+       if (rl->state != isc_ratelimiter_shuttingdown) {
+               rl->state = isc_ratelimiter_shuttingdown;
 
-       while ((event = ISC_LIST_HEAD(rl->pending)) != NULL) {
-               ISC_LIST_UNLINK(rl->pending, event, ev_ratelink);
-               event->ev_attributes |= ISC_EVENTATTR_CANCELED;
-               isc_task_send(event->ev_sender, &event);
+               while ((event = ISC_LIST_HEAD(rl->pending)) != NULL) {
+                       ISC_LIST_UNLINK(rl->pending, event, ev_ratelink);
+                       event->ev_attributes |= ISC_EVENTATTR_CANCELED;
+                       isc_task_send(event->ev_sender, &event);
+               }
+               isc_loop_detach(&rl->loop);
        }
-       isc_loop_detach(&rl->loop);
        UNLOCK(&rl->lock);
 }