commit 823095c: [Minor] Exclude duplicate entries
Vsevolod Stakhov
vsevolod at highsecure.ru
Wed Feb 27 14:28:10 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-02-27 14:26:36 +0000
URL: https://github.com/rspamd/rspamd/commit/823095cd9d08e266aaa1067418a457572a794374 (HEAD -> master)
[Minor] Exclude duplicate entries
---
src/libutil/map_helpers.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/src/libutil/map_helpers.c b/src/libutil/map_helpers.c
index ec4d95183..964e4d98c 100644
--- a/src/libutil/map_helpers.c
+++ b/src/libutil/map_helpers.c
@@ -504,17 +504,25 @@ rspamd_map_helper_insert_hash (gpointer st, gconstpointer key, gconstpointer val
gsize vlen;
gint r;
- vlen = strlen (value);
- val = rspamd_mempool_alloc0 (ht->pool, sizeof (*val) +
- vlen + 1);
- memcpy (val->value, value, vlen);
-
k = kh_get (rspamd_map_hash, ht->htb, key);
+ vlen = strlen (value);
if (k == kh_end (ht->htb)) {
nk = rspamd_mempool_strdup (ht->pool, key);
k = kh_put (rspamd_map_hash, ht->htb, nk, &r);
}
+ else {
+ val = kh_value (ht->htb, k);
+
+ if (strcmp (value, val->value) == 0) {
+ /* Same element, skip */
+ return;
+ }
+ }
+
+ /* Null termination due to alloc0 */
+ val = rspamd_mempool_alloc0 (ht->pool, sizeof (*val) + vlen + 1);
+ memcpy (val->value, value, vlen);
nk = kh_key (ht->htb, k);
val->key = nk;
More information about the Commits
mailing list