]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Fix removing from khash
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 2 Jan 2022 20:49:45 +0000 (20:49 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 2 Jan 2022 20:49:45 +0000 (20:49 +0000)
contrib/librdns/resolver.c
contrib/librdns/util.c
contrib/librdns/util.h

index 05d8383174b5d712afd469886a1970f99e3544f2..c27d9afcc77dd8cde85dca9849ee77613df55a59 100644 (file)
@@ -507,7 +507,7 @@ rdns_process_timer (void *arg)
                        req->async->del_timer (req->async->data,
                                        req->async_event);
                        req->async_event = NULL;
-                       kh_del(rdns_requests_hash, req->io->requests, req->id);
+                       rdns_request_remove_from_hash(req);
                }
 
                /* We have not scheduled timeout actually due to send error */
index 9b74b74666b6ae873ffec679b3dad3224958985f..2fc9ec6c36d555cf27d2b785f38fe0f58f47f9aa 100644 (file)
 #include "logger.h"
 #include "rdns.h"
 
+inline void
+rdns_request_remove_from_hash (struct rdns_request *req)
+{
+       /* Remove from id hashes */
+       if (req->io) {
+               khiter_t k;
+
+               k = kh_get(rdns_requests_hash, req->io->requests, req->id);
+
+               if (k != kh_end(req->io->requests)) {
+                       kh_del(rdns_requests_hash, req->io->requests, req->id);
+               }
+       }
+}
+
 static int
 rdns_make_socket_nonblocking (int fd)
 {
@@ -457,19 +472,14 @@ rdns_request_free (struct rdns_request *req)
                                /* Remove timer */
                                req->async->del_timer (req->async->data,
                                                req->async_event);
-                               /* Remove from id hashes */
-                               if (req->io) {
-                                       kh_del(rdns_requests_hash, req->io->requests, req->id);
-                               }
+                               rdns_request_remove_from_hash(req);
                                req->async_event = NULL;
                        }
                        else if (req->state == RDNS_REQUEST_WAIT_SEND) {
                                /* Remove retransmit event */
                                req->async->del_write (req->async->data,
                                                req->async_event);
-                               if (req->io) {
-                                       kh_del(rdns_requests_hash, req->io->requests, req->id);
-                               }
+                               rdns_request_remove_from_hash(req);
                                req->async_event = NULL;
                        }
                        else if (req->state == RDNS_REQUEST_FAKE) {
@@ -605,19 +615,14 @@ rdns_request_unschedule (struct rdns_request *req)
                if (req->state == RDNS_REQUEST_WAIT_REPLY) {
                        req->async->del_timer (req->async->data,
                                        req->async_event);
-                       /* Remove from id hashes */
-                       if (req->io) {
-                               kh_del(rdns_requests_hash, req->io->requests, req->id);
-                       }
+
                        req->async_event = NULL;
                }
                else if (req->state == RDNS_REQUEST_WAIT_SEND) {
                        req->async->del_write (req->async->data,
                                        req->async_event);
                        /* Remove from id hashes */
-                       if (req->io) {
-                               kh_del(rdns_requests_hash, req->io->requests, req->id);
-                       }
+                       rdns_request_remove_from_hash(req);
                        req->async_event = NULL;
                }
        }
index 5fc94eb8080887a141031fd10dcd0b2b15e357cd..eea818deebc86adf85e8905f78f1c40b59ed362e 100644 (file)
@@ -63,6 +63,12 @@ struct rdns_io_channel * rdns_ioc_new (struct rdns_server *srv,
  */
 void rdns_request_free (struct rdns_request *req);
 
+/**
+ * Removes request from a channel's hash (e.g. if needed to migrate to another channel)
+ * @param req
+ */
+void rdns_request_remove_from_hash (struct rdns_request *req);
+
 /**
  * Free reply
  * @param rep