commit 9117058: [Minor] Allow to specify mempool when copying an IP address structure

Vsevolod Stakhov vsevolod at highsecure.ru
Sun Mar 20 12:49:04 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-03-20 12:45:03 +0000
URL: https://github.com/rspamd/rspamd/commit/9117058f1548c521567e5314280bd484ba039263

[Minor] Allow to specify mempool when copying an IP address structure

---
 src/fuzzy_storage.c               | 6 +++---
 src/libmime/received.cxx          | 2 +-
 src/libserver/http/http_context.c | 2 +-
 src/libutil/addr.c                | 4 ++--
 src/libutil/addr.h                | 2 +-
 src/libutil/upstream.c            | 2 +-
 src/lua/lua_http.c                | 2 +-
 src/lua/lua_ip.c                  | 4 ++--
 src/lua/lua_task.c                | 2 +-
 src/lua/lua_udp.c                 | 2 +-
 src/rspamd.c                      | 4 ++--
 src/rspamd_proxy.c                | 6 +++---
 12 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c
index b9397fc2e..3ed30b179 100644
--- a/src/fuzzy_storage.c
+++ b/src/fuzzy_storage.c
@@ -262,7 +262,7 @@ rspamd_fuzzy_check_ratelimit (struct fuzzy_session *session)
 	}
 	*/
 
-	masked = rspamd_inet_address_copy (session->addr);
+	masked = rspamd_inet_address_copy(session->addr, NULL);
 
 	if (rspamd_inet_address_get_af (masked) == AF_INET) {
 		rspamd_inet_address_apply_mask (masked,
@@ -1098,7 +1098,7 @@ rspamd_fuzzy_process_command (struct fuzzy_session *session)
 				session->addr, -1);
 
 		if (ip_stat == NULL) {
-			naddr = rspamd_inet_address_copy (session->addr);
+			naddr = rspamd_inet_address_copy(session->addr, NULL);
 			ip_stat = g_malloc0 (sizeof (*ip_stat));
 			REF_INIT_RETAIN (ip_stat, fuzzy_key_stat_dtor);
 			rspamd_lru_hash_insert (session->key_stat->last_ips,
@@ -1662,7 +1662,7 @@ accept_fuzzy_socket (EV_P_ ev_io *w, int revents)
 						nerrors = g_malloc (sizeof (*nerrors));
 						*nerrors = 1;
 						rspamd_lru_hash_insert (session->ctx->errors_ips,
-								rspamd_inet_address_copy (session->addr),
+								rspamd_inet_address_copy(session->addr, NULL),
 								nerrors, -1, -1);
 					}
 					else {
diff --git a/src/libmime/received.cxx b/src/libmime/received.cxx
index 9571580e9..0886d6e37 100644
--- a/src/libmime/received.cxx
+++ b/src/libmime/received.cxx
@@ -737,7 +737,7 @@ received_maybe_fix_task(struct rspamd_task *task) -> bool
 				if (mta_name) {
 					trecv.by_hostname.assign_copy(std::string_view(mta_name));
 				}
-				trecv.addr = rspamd_inet_address_copy(task->from_addr);
+				trecv.addr = rspamd_inet_address_copy(task->from_addr, NULL);
 
 				if (task->hostname) {
 					trecv.real_hostname.assign_copy(std::string_view(task->hostname));
diff --git a/src/libserver/http/http_context.c b/src/libserver/http/http_context.c
index e86d8ae79..87ee9268e 100644
--- a/src/libserver/http/http_context.c
+++ b/src/libserver/http/http_context.c
@@ -539,7 +539,7 @@ rspamd_http_context_prepare_keepalive(struct rspamd_http_context *ctx,
 		phk->conns = empty_init;
 		phk->host = g_strdup (host);
 		phk->is_ssl = is_ssl;
-		phk->addr = rspamd_inet_address_copy (addr);
+		phk->addr = rspamd_inet_address_copy(addr, NULL);
 		phk->port = hk.port;
 
 
diff --git a/src/libutil/addr.c b/src/libutil/addr.c
index b19182514..d5502fce0 100644
--- a/src/libutil/addr.c
+++ b/src/libutil/addr.c
@@ -1832,7 +1832,7 @@ rspamd_inet_address_compare_ptr (gconstpointer a1,
 }
 
 rspamd_inet_addr_t *
-rspamd_inet_address_copy (const rspamd_inet_addr_t *addr)
+rspamd_inet_address_copy(const rspamd_inet_addr_t *addr, rspamd_mempool_t *pool)
 {
 	rspamd_inet_addr_t *n;
 
@@ -1840,7 +1840,7 @@ rspamd_inet_address_copy (const rspamd_inet_addr_t *addr)
 		return NULL;
 	}
 
-	n = rspamd_inet_addr_create (addr->af, NULL);
+	n = rspamd_inet_addr_create (addr->af, pool);
 
 	if (n->af == AF_UNIX) {
 		memcpy (n->u.un, addr->u.un, sizeof (*addr->u.un));
diff --git a/src/libutil/addr.h b/src/libutil/addr.h
index 832245a49..a839783b8 100644
--- a/src/libutil/addr.h
+++ b/src/libutil/addr.h
@@ -322,7 +322,7 @@ gint rspamd_inet_address_compare_ptr (gconstpointer a1,
  * @param addr
  * @return
  */
-rspamd_inet_addr_t *rspamd_inet_address_copy (const rspamd_inet_addr_t *addr);
+rspamd_inet_addr_t *rspamd_inet_address_copy(const rspamd_inet_addr_t *addr, rspamd_mempool_t *pool);
 
 /**
  * Returns hash for inet address (ignoring port)
diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c
index 30c53daee..7eb3e402e 100644
--- a/src/libutil/upstream.c
+++ b/src/libutil/upstream.c
@@ -1167,7 +1167,7 @@ rspamd_upstreams_add_upstream (struct upstream_list *ups, const gchar *str,
 		}
 		for (i = 0; i < addrs->len; i ++) {
 			addr = g_ptr_array_index (addrs, i);
-			rspamd_upstream_add_addr (upstream, rspamd_inet_address_copy (addr));
+			rspamd_upstream_add_addr (upstream, rspamd_inet_address_copy(addr, NULL));
 		}
 	}
 
diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c
index c95f2dd0d..51fe1f272 100644
--- a/src/lua/lua_http.c
+++ b/src/lua/lua_http.c
@@ -1078,7 +1078,7 @@ lua_http_request (lua_State *L)
 					msg->flags & RSPAMD_HTTP_FLAG_WANT_SSL);
 
 			if (ka_addr) {
-				cbd->addr = rspamd_inet_address_copy(ka_addr);
+				cbd->addr = rspamd_inet_address_copy(ka_addr, NULL);
 				numeric_ip = true;
 			}
 		}
diff --git a/src/lua/lua_ip.c b/src/lua/lua_ip.c
index dc51a83e9..ad2e2e8b0 100644
--- a/src/lua/lua_ip.c
+++ b/src/lua/lua_ip.c
@@ -210,7 +210,7 @@ lua_ip_new (lua_State *L, struct rspamd_lua_ip *old)
 	ip = g_malloc0 (sizeof (*ip));
 
 	if (old != NULL && old->addr != NULL) {
-		ip->addr = rspamd_inet_address_copy (old->addr);
+		ip->addr = rspamd_inet_address_copy(old->addr, NULL);
 	}
 
 	pip = lua_newuserdata (L, sizeof (struct rspamd_lua_ip *));
@@ -589,7 +589,7 @@ rspamd_lua_ip_push (lua_State *L, rspamd_inet_addr_t *addr)
 	struct rspamd_lua_ip *ip, **pip;
 
 	ip = g_malloc0 (sizeof (struct rspamd_lua_ip));
-	ip->addr = rspamd_inet_address_copy (addr);
+	ip->addr = rspamd_inet_address_copy(addr, NULL);
 	pip = lua_newuserdata (L, sizeof (struct rspamd_lua_ip *));
 	rspamd_lua_setclass (L, "rspamd{ip}", -1);
 	*pip = ip;
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 011950125..2b811f4a7 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -4272,7 +4272,7 @@ lua_task_set_from_ip (lua_State *L)
 					rspamd_inet_address_free (task->from_addr);
 				}
 
-				task->from_addr = rspamd_inet_address_copy (ip->addr);
+				task->from_addr = rspamd_inet_address_copy(ip->addr, NULL);
 			}
 			else {
 				return luaL_error (L, "invalid IP object");
diff --git a/src/lua/lua_udp.c b/src/lua/lua_udp.c
index 656d80349..4f5696a94 100644
--- a/src/lua/lua_udp.c
+++ b/src/lua/lua_udp.c
@@ -397,7 +397,7 @@ lua_udp_sendto (lua_State *L) {
 				return luaL_error (L, "invalid host class");
 			}
 
-			addr = rspamd_inet_address_copy (lip->addr);
+			addr = rspamd_inet_address_copy(lip->addr, NULL);
 
 			if (port != 0) {
 				rspamd_inet_address_set_port (addr, port);
diff --git a/src/rspamd.c b/src/rspamd.c
index 610c9aa7b..230206add 100644
--- a/src/rspamd.c
+++ b/src/rspamd.c
@@ -413,7 +413,7 @@ create_listen_socket (GPtrArray *addrs, guint cnt,
 					listen_opts, -1);
 			if (fd != -1) {
 				ls = g_malloc0 (sizeof (*ls));
-				ls->addr = rspamd_inet_address_copy (g_ptr_array_index (addrs, i));
+				ls->addr = rspamd_inet_address_copy(g_ptr_array_index (addrs, i), NULL);
 				ls->fd = fd;
 				ls->type = RSPAMD_WORKER_SOCKET_TCP;
 				result = g_list_prepend (result, ls);
@@ -425,7 +425,7 @@ create_listen_socket (GPtrArray *addrs, guint cnt,
 					listen_opts | RSPAMD_INET_ADDRESS_LISTEN_REUSEPORT, -1);
 			if (fd != -1) {
 				ls = g_malloc0 (sizeof (*ls));
-				ls->addr = rspamd_inet_address_copy (g_ptr_array_index (addrs, i));
+				ls->addr = rspamd_inet_address_copy(g_ptr_array_index (addrs, i), NULL);
 				ls->fd = fd;
 				ls->type = RSPAMD_WORKER_SOCKET_UDP;
 				result = g_list_prepend (result, ls);
diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c
index 13393660e..10f95e0bf 100644
--- a/src/rspamd_proxy.c
+++ b/src/rspamd_proxy.c
@@ -1804,11 +1804,11 @@ rspamd_proxy_self_scan (struct rspamd_proxy_session *session)
 	task->sock = -1;
 
 	if (session->client_milter_conn) {
-		task->client_addr = rspamd_inet_address_copy (
-				session->client_milter_conn->addr);
+		task->client_addr = rspamd_inet_address_copy(
+				session->client_milter_conn->addr, NULL);
 	}
 	else {
-		task->client_addr = rspamd_inet_address_copy (session->client_addr);
+		task->client_addr = rspamd_inet_address_copy(session->client_addr, NULL);
 	}
 
 	task->fin_arg = session;


More information about the Commits mailing list