Skip to content

Commit 9595f0e

Browse files
committed
Free socket on SSL failure
SSL_set_fd(3) does not consume the file descriptor.
1 parent 34770be commit 9595f0e

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/netlog/netlog-dtls.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ int dtls_connect(DTLSManager *m, SocketAddress *address) {
6464
.tv_sec = 3,
6565
.tv_usec = 0,
6666
};
67-
int fd, r;
67+
_cleanup_close_ int fd = -1;
68+
int r;
6869

6970
assert(m);
7071
assert(address);
@@ -158,7 +159,7 @@ int dtls_connect(DTLSManager *m, SocketAddress *address) {
158159

159160
m->ssl = TAKE_PTR(ssl);
160161
m->ctx = ctx;
161-
m->fd = fd;
162+
m->fd = TAKE_FD(fd);
162163

163164
m->connected = true;
164165
return 0;
@@ -199,6 +200,7 @@ int dtls_manager_init(OpenSSLCertificateAuthMode auth_mode, DTLSManager **ret) {
199200

200201
*m = (DTLSManager) {
201202
.auth_mode = auth_mode,
203+
.fd = -1,
202204
};
203205

204206
*ret = TAKE_PTR(m);

src/netlog/netlog-tls.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ int tls_connect(TLSManager *m, SocketAddress *address) {
6969
const SSL_CIPHER *cipher;
7070
socklen_t salen;
7171
SSL_CTX *ctx;
72-
int fd, r;
72+
_cleanup_close_ int fd = -1;
73+
int r;
7374

7475
assert(m);
7576
assert(address);
@@ -158,7 +159,7 @@ int tls_connect(TLSManager *m, SocketAddress *address) {
158159

159160
m->ssl = TAKE_PTR(ssl);
160161
m->ctx = ctx;
161-
m->fd = fd;
162+
m->fd = TAKE_FD(fd);
162163

163164
m->connected = true;
164165
return 0;
@@ -199,6 +200,7 @@ int tls_manager_init(OpenSSLCertificateAuthMode auth, TLSManager **ret ) {
199200

200201
*m = (TLSManager) {
201202
.auth_mode = auth,
203+
.fd = -1,
202204
};
203205

204206
*ret = TAKE_PTR(m);

0 commit comments

Comments
 (0)