changeset 21903:d67d1a1edae0

lib-imap-client: Do not reset ips when reconnecting Avoids infinite loop
author Aki Tuomi <aki.tuomi@dovecot.fi>
date Wed, 05 Apr 2017 14:22:38 +0300
parents 1a8d0b40e6a4
children f9c13c7c7be2
files src/lib-imap-client/imapc-connection.c
diffstat 1 files changed, 10 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-imap-client/imapc-connection.c	Wed Apr 05 13:27:57 2017 +0300
+++ b/src/lib-imap-client/imapc-connection.c	Wed Apr 05 14:22:38 2017 +0300
@@ -373,18 +373,17 @@
 			i_free_and_null(conn->disconnect_reason);
 		}
 		reply.text_without_resp = reply.text_full;
-		if (!conn->reconnecting)
+		if (!conn->reconnecting) {
 			imapc_login_callback(conn, &reply);
-
+			i_free(conn->ips);
+			conn->ips_count = 0;
+		}
 		conn->idling = FALSE;
 		conn->idle_plus_waiting = FALSE;
 		conn->idle_stopping = FALSE;
 
 		conn->selecting_box = NULL;
 		conn->selected_box = NULL;
-
-		i_free(conn->ips);
-		conn->ips_count = 0;
 		break;
 	default:
 		break;
@@ -1830,8 +1829,9 @@
 	dns_set.timeout_msecs = conn->client->set.connect_timeout_msecs;
 
 	imapc_connection_set_state(conn, IMAPC_CONNECTION_STATE_CONNECTING);
-	if (conn->ips_count == 0 &&
-	    net_addr2ip(conn->client->set.host, &ip) == 0) {
+	if (conn->ips_count > 0) {
+		/* do nothing */
+	} else if (net_addr2ip(conn->client->set.host, &ip) == 0) {
 		conn->ips_count = 1;
 		conn->ips = i_new(struct ip_addr, conn->ips_count);
 		conn->ips[0] = ip;
@@ -1848,15 +1848,13 @@
 		conn->ips_count = ips_count;
 		conn->ips = i_new(struct ip_addr, ips_count);
 		memcpy(conn->ips, ips, ips_count * sizeof(*ips));
-	}
-
-	if (conn->ips_count == 0) {
+	} else {
 		(void)dns_lookup(conn->client->set.host, &dns_set,
 				 imapc_connection_dns_callback, conn,
 				 &conn->dns_lookup);
-	} else {
-		imapc_connection_connect_next_ip(conn);
+		return;
 	}
+	imapc_connection_connect_next_ip(conn);
 }
 
 void imapc_connection_input_pending(struct imapc_connection *conn)