dial: freeaddrinfo on failure on reconnect - irc - IRC client based on c9x.me/irc client (HTM) git clone git://git.codemadness.org/irc (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit 3f3d05fe79f64a4312664e8607d5bd71b3e73b52 (DIR) parent 2f85ad5b356490f957cd52d81f55624eff08bdd7 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org> Date: Mon, 31 Jul 2017 18:28:05 +0200 dial: freeaddrinfo on failure on reconnect Diffstat: M irc.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) --- (DIR) diff --git a/irc.c b/irc.c @@ -234,6 +234,7 @@ static char * dial(const char *host, const char *service) { struct addrinfo hints, *res = NULL, *rp; + char *err = 0; int fd = -1, e; memset(&hints, 0, sizeof(hints)); @@ -251,19 +252,28 @@ dial(const char *host, const char *service) } break; } - if (fd == -1) - return "Cannot connect to host."; + if (fd == -1) { + err = "Cannot connect to host."; + goto fail; + } srv.fd = fd; if (ssl) { - if (tls_init() < 0) - return "Could not initialize TLS."; - if (!(srv.tls = tls_client())) - return "Could not initialize TLS context."; - if (tls_connect_socket(srv.tls, srv.fd, host) < 0) - return "Could not connect with ssl."; + if (tls_init() < 0) { + err = "Could not initialize TLS."; + goto fail; + } + if (!(srv.tls = tls_client())) { + err = "Could not initialize TLS context."; + goto fail; + } + if (tls_connect_socket(srv.tls, srv.fd, host) < 0) { + err = "Could not connect with ssl."; + goto fail; + } } +fail: freeaddrinfo(res); - return 0; + return err; } static void