]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
close FD on error in more cases
authorAlan T. DeKok <aland@freeradius.org>
Thu, 10 Nov 2022 17:01:13 +0000 (17:01 +0000)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 10 Nov 2022 17:01:13 +0000 (17:01 +0000)
src/main/listen.c

index 43ced2cce0157cac8e5d53826dc5c7346997240e..7d137318aef78ee9be19f44cc92b4742f8aa89e9 100644 (file)
@@ -3134,6 +3134,8 @@ rad_listen_t *proxy_new_listener(TALLOC_CTX *ctx, home_server_t *home, uint16_t
                if (this->nonblock) {
                        if (fr_nonblock(this->fd) < 0) {
                                ERROR("(TLS) Failed setting nonblocking for proxy socket '%s' - %s", buffer, fr_strerror());
+                       error:
+                               close(this->fd);
                                home->last_failed_open = now;
                                listen_free(&this);
                                return NULL;
@@ -3143,8 +3145,7 @@ rad_listen_t *proxy_new_listener(TALLOC_CTX *ctx, home_server_t *home, uint16_t
 
                        if (!rbtree_insert(home->listeners, this)) {
                                ERROR("(TLS) Failed adding tracking informtion for proxy socket '%s'", buffer);
-                               listen_free(&this);
-                               return NULL;
+                               goto error;
                        }
                }
 
@@ -3154,9 +3155,7 @@ rad_listen_t *proxy_new_listener(TALLOC_CTX *ctx, home_server_t *home, uint16_t
                sock->ssn = tls_new_client_session(sock, home->tls, this->fd, &sock->certs);
                if (!sock->ssn) {
                        ERROR("(TLS) Failed opening connection on proxy socket '%s'", buffer);
-                       home->last_failed_open = now;
-                       listen_free(&this);
-                       return NULL;
+                       goto error;
                }
 
                sock->connect_timeout = home->connect_timeout;
@@ -3222,17 +3221,13 @@ rad_listen_t *proxy_new_listener(TALLOC_CTX *ctx, home_server_t *home, uint16_t
                                &sizeof_src) < 0) {
                        ERROR("Failed getting socket name for '%s': %s",
                              buffer, fr_syserror(errno));
-                       home->last_failed_open = now;
-                       listen_free(&this);
-                       return NULL;
+                       goto error;
                }
 
                if (!fr_sockaddr2ipaddr(&src, sizeof_src,
                                        &sock->my_ipaddr, &sock->my_port)) {
                        ERROR("Socket has unsupported address family for '%s'", buffer);
-                       home->last_failed_open = now;
-                       listen_free(&this);
-                       return NULL;
+                       goto error;
                }
 
                this->print(this, buffer, sizeof(buffer));