From f467c031c1812c8ec94decd89072a6207ce24e41 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sat, 22 Apr 2023 14:36:21 +0200 Subject: [PATCH] Fix memory leak when an outgoing TLS_connect() fails. Reported by immibis in https://bugs.unrealircd.org/view.php?id=6263 --- doc/RELEASE-NOTES.md | 1 + src/tls.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/doc/RELEASE-NOTES.md b/doc/RELEASE-NOTES.md index c4a23df7c..33d278111 100644 --- a/doc/RELEASE-NOTES.md +++ b/doc/RELEASE-NOTES.md @@ -113,6 +113,7 @@ HELPOP updates, fixes for streaming logs over websockets, ban exemption change a * Crash if there is a parse error in an included file and there are other remote included files still being downloaded. * Memory leak in WHOWAS +* Memory leak when connecting to a TLS server fails * Workaround a bug in some websocket implementations where the WSOP_PONG frame is unmasked (now permitted). diff --git a/src/tls.c b/src/tls.c index eb76c0052..11b460acc 100644 --- a/src/tls.c +++ b/src/tls.c @@ -692,7 +692,14 @@ void unreal_tls_client_handshake(int fd, int revents, void *data) switch (unreal_tls_connect(client, fd)) { case -1: + SSL_set_shutdown(client->local->ssl, SSL_RECEIVED_SHUTDOWN); + SSL_smart_shutdown(client->local->ssl); + SSL_free(client->local->ssl); + client->local->ssl = NULL; + ClearTLS(client); + SetDeadSocket(client); fd_close(fd); + fd_unnotify(fd); client->local->fd = -1; --OpenFiles; return;