commit 635709b: [Minor] Fix hash usage after rework to address pointer stability issue
Vsevolod Stakhov
vsevolod at rspamd.com
Mon Jul 18 08:21:03 UTC 2022
Author: Vsevolod Stakhov
Date: 2022-07-18 09:19:26 +0100
URL: https://github.com/rspamd/rspamd/commit/635709b5acfd7717e75b7e52a8bdf0988117c825 (HEAD -> master)
[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 <list>
#include "contrib/ankerl/unordered_dense.h"
+#include <list>
+#include <unordered_map>
+
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<redisAsyncContext *,
redis_pool_connection *> conns_by_ctx;
- ankerl::unordered_dense::map<redis_pool_key_t, redis_pool_elt> 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<redis_pool_key_t, redis_pool_elt> 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();
}
More information about the Commits
mailing list