diff --git a/src/net.c b/src/net.c index c64aa5a..c3e8694 100644 --- a/src/net.c +++ b/src/net.c @@ -187,11 +187,11 @@ int tcp_connect(struct ev_loop *loop, const char *host, int port, if (ret) { if (ret == EAI_SYSTEM) { log_err("getaddrinfo failed: %s\n", strerror(errno)); - return -1; + goto fail; } log_err("getaddrinfo failed: %s\n", gai_strerror(ret)); - return -1; + goto fail; } for (rp = result; rp != NULL; rp = rp->ai_next) { @@ -211,5 +211,8 @@ int tcp_connect(struct ev_loop *loop, const char *host, int port, free_addrinfo: freeaddrinfo(result); +fail: + if (sock < 0) + on_connected(-1, arg); return sock; } diff --git a/src/rtty.c b/src/rtty.c index 5107192..f703643 100644 --- a/src/rtty.c +++ b/src/rtty.c @@ -772,13 +772,13 @@ int rtty_start(struct rtty *rtty) ev_init(&rtty->tmr, rtty_timer_cb); + INIT_LIST_HEAD(&rtty->ttys); + INIT_LIST_HEAD(&rtty->http_conns); + if (tcp_connect(rtty->loop, rtty->host, rtty->port, on_net_connected, rtty) < 0 && !rtty->reconnect) return -1; - INIT_LIST_HEAD(&rtty->ttys); - INIT_LIST_HEAD(&rtty->http_conns); - return 0; }