From 48208dfdc5f94d4f7a2668d52d679841a7c0ce92 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 14 Mar 2016 18:45:06 +0000 Subject: [PATCH] [Fix] More fixes to maps resources management --- src/libutil/map.c | 55 ++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/src/libutil/map.c b/src/libutil/map.c index 972cae2d2..e6f185a39 100644 --- a/src/libutil/map.c +++ b/src/libutil/map.c @@ -65,6 +65,9 @@ write_http_request (struct http_callback_data *cbd) msg->url = rspamd_fstring_new_init (cbd->data->path, strlen (cbd->data->path)); msg->url = rspamd_fstring_append (msg->url, ".sig", 4); } + else { + g_assert_not_reached (); + } rspamd_http_connection_write_message (cbd->conn, msg, cbd->data->host, NULL, cbd, cbd->fd, &cbd->tv, cbd->ev_base); @@ -73,7 +76,6 @@ write_http_request (struct http_callback_data *cbd) else { msg_err_pool ("cannot connect to %s: %s", cbd->data->host, strerror (errno)); - REF_RELEASE (cbd); } } @@ -225,6 +227,10 @@ free_http_cbdata (struct http_callback_data *cbd) close (cbd->fd); } + if (cbd->addr) { + rspamd_inet_address_destroy (cbd->addr); + } + g_slice_free1 (sizeof (struct http_callback_data), cbd); } @@ -563,11 +569,6 @@ rspamd_map_dns_callback (struct rdns_reply *reply, void *arg) struct http_callback_data *cbd = arg; rspamd_mempool_t *pool; - if (cbd->stage >= map_load_file) { - /* No need in further corrections */ - return; - } - pool = cbd->map->pool; if (reply->code == RDNS_RC_NOERROR) { @@ -575,28 +576,32 @@ rspamd_map_dns_callback (struct rdns_reply *reply, void *arg) * We just get the first address hoping that a resolver performs * round-robin rotation well */ - cbd->addr = rspamd_inet_address_from_rnds (reply->entries); - - - if (cbd->addr != NULL) { - rspamd_inet_address_set_port (cbd->addr, cbd->data->port); - /* Try to open a socket */ - - cbd->fd = rspamd_inet_address_connect (cbd->addr, SOCK_STREAM, TRUE); - - if (cbd->fd != -1) { - cbd->stage = map_load_file; - cbd->conn = rspamd_http_connection_new (http_map_read, - http_map_error, http_map_finish, - RSPAMD_HTTP_BODY_PARTIAL|RSPAMD_HTTP_CLIENT_SIMPLE, - RSPAMD_HTTP_CLIENT, NULL); - - write_http_request (cbd); + if (cbd->addr == NULL) { + cbd->addr = rspamd_inet_address_from_rnds (reply->entries); + + if (cbd->addr != NULL) { + rspamd_inet_address_set_port (cbd->addr, cbd->data->port); + /* Try to open a socket */ + cbd->fd = rspamd_inet_address_connect (cbd->addr, SOCK_STREAM, + TRUE); + + if (cbd->fd != -1) { + cbd->stage = map_load_file; + cbd->conn = rspamd_http_connection_new (http_map_read, + http_map_error, http_map_finish, + RSPAMD_HTTP_BODY_PARTIAL|RSPAMD_HTTP_CLIENT_SIMPLE, + RSPAMD_HTTP_CLIENT, NULL); + + write_http_request (cbd); + } + else { + rspamd_inet_address_destroy (cbd->addr); + cbd->addr = NULL; + } } } } - - if (cbd->stage < map_load_file) { + else if (cbd->stage < map_load_file) { if (cbd->stage == map_resolve_host2) { /* We have still one request pending */ cbd->stage = map_resolve_host1; -- 2.39.5