commit cf6947e: [Minor] Sanity check as ctors order is not defined

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Apr 16 09:56:04 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-04-16 10:55:12 +0100
URL: https://github.com/rspamd/rspamd/commit/cf6947e857f16a48652abd2a77becf6c05a6c106 (HEAD -> master)

[Minor] Sanity check as ctors order is not defined
Issue: #3721

---
 src/libutil/mem_pool.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/libutil/mem_pool.c b/src/libutil/mem_pool.c
index b92579e36..7ade92440 100644
--- a/src/libutil/mem_pool.c
+++ b/src/libutil/mem_pool.c
@@ -129,7 +129,9 @@ rspamd_mempool_entry_new (const gchar *loc)
 
 RSPAMD_CONSTRUCTOR (rspamd_mempool_entries_ctor)
 {
-	mempool_entries = kh_init (mempool_entry);
+	if (mempool_entries == NULL) {
+		mempool_entries = kh_init (mempool_entry);
+	}
 }
 
 RSPAMD_DESTRUCTOR (rspamd_mempool_entries_dtor)
@@ -150,6 +152,10 @@ rspamd_mempool_get_entry (const gchar *loc)
 	khiter_t k;
 	struct rspamd_mempool_entry_point *elt;
 
+	if (G_UNLIKELY (!mempool_entries)) {
+		rspamd_mempool_entries_ctor();
+	}
+
 	k = kh_get (mempool_entry, mempool_entries, loc);
 
 	if (k != kh_end (mempool_entries)) {
@@ -158,10 +164,9 @@ rspamd_mempool_get_entry (const gchar *loc)
 		return elt;
 	}
 
-	return rspamd_mempool_entry_new (loc);
+	return rspamd_mempool_entry_new(loc);
 }
 
-
 static struct _pool_chain *
 rspamd_mempool_chain_new (gsize size, enum rspamd_mempool_chain_type pool_type)
 {


More information about the Commits mailing list