]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
anvil: connect_limit_deinit() - Free ident_pid_hash elements
authorMartti Rannanjärvi <martti.rannanjarvi@open-xchange.com>
Fri, 4 Feb 2022 02:30:48 +0000 (04:30 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Mon, 21 Feb 2022 10:18:30 +0000 (10:18 +0000)
src/anvil/connect-limit.c

index 0548a0b7898fc008bff2bccefd9b7da966ce2e64..0d27368b60df623ac432f5dfcda8a1cecb91e65e 100644 (file)
@@ -21,6 +21,9 @@ struct connect_limit {
        HASH_TABLE(struct ident_pid *, struct ident_pid *) ident_pid_hash;
 };
 
+static void
+connect_limit_ident_hash_unref(struct connect_limit *limit, const char *ident);
+
 static unsigned int ident_pid_hash(const struct ident_pid *i)
 {
        return str_hash(i->ident) ^ i->pid;
@@ -50,6 +53,17 @@ struct connect_limit *connect_limit_init(void)
 void connect_limit_deinit(struct connect_limit **_limit)
 {
        struct connect_limit *limit = *_limit;
+       struct hash_iterate_context *iter;
+       struct ident_pid *i, *value;
+
+       iter = hash_table_iterate_init(limit->ident_pid_hash);
+       while (hash_table_iterate(iter, limit->ident_pid_hash, &i, &value)) {
+               hash_table_remove(limit->ident_pid_hash, i);
+               for (; i->refcount > 0; i->refcount--)
+                       connect_limit_ident_hash_unref(limit, i->ident);
+               i_free(i);
+       }
+       hash_table_iterate_deinit(&iter);
 
        *_limit = NULL;
        hash_table_destroy(&limit->ident_hash);