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/librdns/util.c | |
parent | af3994ae7d27e935228fb866103d94310de974c3 (diff) | |
download | rspamd-5381697dbc3507705d3f9f6e0946e0982242eaff.tar.gz rspamd-5381697dbc3507705d3f9f6e0946e0982242eaff.zip |
[Fix] Fix removing from khash
Diffstat (limited to 'contrib/librdns/util.c')
-rw-r--r-- | contrib/librdns/util.c | 33 |
1 files changed, 19 insertions, 14 deletions
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; } } |