Blob Blame History Raw
commit 06d06ff9477780d82ef3a1851525e3bc2aa4280f
Author: dormando <dormando@rydia.net>
Date:   Fri Sep 20 12:39:30 2019 -0700

    TLS: fix leak of SSL context on accept failure
    
    frees said context. Don't use SSL_Shutdown as connection was not
    established.
    
    also fixes potential leak if dispatch_conn_new fails; but that
    shouldn't be possible for most systems. requires either a malloc
    failure or event_add() failure.

diff --git a/memcached.c b/memcached.c
index e8c0da4..1be6583 100644
--- a/memcached.c
+++ b/memcached.c
@@ -5805,6 +5805,7 @@ static void drive_machine(conn *c) {
                             if (settings.verbose) {
                                 fprintf(stderr, "SSL connection failed with error code : %d : %s\n", err, strerror(errno));
                             }
+                            SSL_free(ssl);
                             close(sfd);
                             break;
                         }
diff --git a/thread.c b/thread.c
index f3a08ad..eaec647 100644
--- a/thread.c
+++ b/thread.c
@@ -500,6 +500,12 @@ static void thread_libevent_process(int fd, short which, void *arg) {
                             fprintf(stderr, "Can't listen for events on fd %d\n",
                                 item->sfd);
                         }
+#ifdef TLS
+                        if (item->ssl) {
+                            SSL_shutdown(item->ssl);
+                            SSL_free(item->ssl);
+                        }
+#endif
                         close(item->sfd);
                     }
                 } else {