From 635709b5acfd7717e75b7e52a8bdf0988117c825 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 18 Jul 2022 09:19:26 +0100 Subject: [PATCH] [Minor] Fix hash usage after rework to address pointer stability issue --- src/libserver/redis_pool.cxx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libserver/redis_pool.cxx b/src/libserver/redis_pool.cxx index 2ea8b727c..19acaa828 100644 --- a/src/libserver/redis_pool.cxx +++ b/src/libserver/redis_pool.cxx @@ -23,9 +23,11 @@ #include "contrib/hiredis/adapters/libev.h" #include "cryptobox.h" #include "logger.h" -#include #include "contrib/ankerl/unordered_dense.h" +#include +#include + namespace rspamd { class redis_pool_elt; class redis_pool; @@ -201,7 +203,11 @@ class redis_pool final { /* We want to have references integrity */ ankerl::unordered_dense::map conns_by_ctx; - ankerl::unordered_dense::map elts_by_key; + /* + * We store a pointer to the element in each connection, so this has to be + * a buckets map with pointers/references stability guarantees. + */ + std::unordered_map elts_by_key; bool wanna_die = false; /* Hiredis is 'clever' so we can call ourselves from destructor */ public: double timeout = default_timeout; @@ -495,9 +501,8 @@ redis_pool::new_connection(const gchar *db, const gchar *password, } else { /* Need to create a pool */ - auto nconn = redis_pool_elt{this, db, password, ip, port}; auto nelt = elts_by_key.try_emplace(key, - std::move(nconn)); + this, db, password, ip, port); return nelt.first->second.new_connection(); } -- 2.39.5