diff --git a/https.c b/https.c index bc22da4..9d06447 100644 --- a/https.c +++ b/https.c @@ -290,8 +290,12 @@ _establish_connection(struct https_request * const req, if (connected_socket == -1) { continue; } - sock_flags = fcntl(connected_socket, F_GETFL, 0); - fcntl(connected_socket, F_SETFL, sock_flags|O_NONBLOCK); + if ((sock_flags = fcntl(connected_socket, F_GETFL, 0)) == -1) { + goto fail; + } + if (fcntl(connected_socket, F_SETFL, sock_flags|O_NONBLOCK) == -1) { + goto fail; + } if (connect(connected_socket, cur_res->ai_addr, cur_res->ai_addrlen) != 0 && errno != EINPROGRESS) { @@ -301,12 +305,13 @@ _establish_connection(struct https_request * const req, } socket_error = _fd_wait(connected_socket, 10000); if (socket_error != 1) { - close(connected_socket); - connected_socket = -1; - continue; + goto fail; } /* Connected! */ break; + fail: + close(connected_socket); + connected_socket = -1; } } cur_res = NULL; @@ -339,8 +344,10 @@ https_init(const char *useragent, const char *cafile, const char *proxy) BIO *bio; char *p; - if ((ctx = calloc(1, sizeof(*ctx))) == NULL || - (ctx->useragent = strdup(useragent)) == NULL) { + if ((ctx = calloc(1, sizeof(*ctx))) == NULL) { + return (HTTPS_ERR_SYSTEM); + } + if ((ctx->useragent = strdup(useragent)) == NULL) { ctx->errstr = strerror(errno); return (HTTPS_ERR_SYSTEM); }