diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2022-01-02 20:49:45 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2022-01-02 20:49:45 +0000 |
commit | 5381697dbc3507705d3f9f6e0946e0982242eaff (patch) | |
tree | bc3ac377f7d4b1eb853513e200cefb6e65af33a1 /contrib | |
parent | af3994ae7d27e935228fb866103d94310de974c3 (diff) | |
download | rspamd-5381697dbc3507705d3f9f6e0946e0982242eaff.tar.gz rspamd-5381697dbc3507705d3f9f6e0946e0982242eaff.zip |
[Fix] Fix removing from khash
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/librdns/resolver.c | 2 | ||||
-rw-r--r-- | contrib/librdns/util.c | 33 | ||||
-rw-r--r-- | contrib/librdns/util.h | 6 |
3 files changed, 26 insertions, 15 deletions
diff --git a/contrib/librdns/resolver.c b/contrib/librdns/resolver.c index 05d838317..c27d9afcc 100644 --- a/contrib/librdns/resolver.c +++ b/contrib/librdns/resolver.c @@ -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 */ diff --git a/contrib/librdns/util.c b/contrib/librdns/util.c index 9b74b7466..2fc9ec6c3 100644 --- a/contrib/librdns/util.c +++ b/contrib/librdns/util.c @@ -40,6 +40,21 @@ #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; } } diff --git a/contrib/librdns/util.h b/contrib/librdns/util.h index 5fc94eb80..eea818dee 100644 --- a/contrib/librdns/util.h +++ b/contrib/librdns/util.h @@ -64,6 +64,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 */ |