Fix crash at client disconnect when using PolarSSL >= 1.2.6
authorMartin Johansson <martin@fatbob.nu>
Tue, 14 May 2013 20:36:13 +0000 (22:36 +0200)
committerMartin Johansson <martin@fatbob.nu>
Tue, 14 May 2013 20:36:13 +0000 (22:36 +0200)
src/ssl.c

index 2218864868e39daa3cdea1a04666e8ec863e91f9..86e35a5f1fed9dd795cba995cf18d21dd35ff7cb 100644 (file)
--- a/src/ssl.c
+++ b/src/ssl.c
@@ -154,7 +154,7 @@ static void initKey()
 int urandom_bytes(void *ctx, unsigned char *dest, size_t len)
 {
        int cur;
-
+       
        while (len) {
                cur = read(urandom_fd, dest, len);
                if (cur < 0)
@@ -275,7 +275,7 @@ int SSLi_nonblockaccept(SSL_handle_t *ssl, bool_t *SSLready)
        if (rc != 0) {
                if (rc == POLARSSL_ERR_NET_WANT_READ || rc == POLARSSL_ERR_NET_WANT_WRITE) {
                        return 0;
-               } else if (POLARSSL_ERR_X509_CERT_VERIFY_FAILED) { /* Allow this (selfsigned etc) */
+               } else if (rc == POLARSSL_ERR_X509_CERT_VERIFY_FAILED) { /* Allow this (selfsigned etc) */
                        return 0;                       
                } else {
                        Log_warn("SSL handshake failed: %d", rc);
@@ -324,7 +324,10 @@ void SSLi_shutdown(SSL_handle_t *ssl)
 void SSLi_free(SSL_handle_t *ssl)
 {
        Log_debug("SSLi_free");
-       free(ssl->session); /* XXX - Hmmm. */
+#if (POLARSSL_VERSION_MINOR <= 2 && POLARSSL_VERSION_PATCH < 6)
+       free(ssl->session); /* Workaround for memory leak in PolarSSL < 1.2.6 */
+       ssl->session = NULL;
+#endif
        ssl_free(ssl);
        free(ssl);
 }