]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
OpenSSL: Fix memory leak on error path
authorJouni Malinen <j@w1.fi>
Sat, 26 Oct 2013 09:02:50 +0000 (12:02 +0300)
committerJouni Malinen <j@w1.fi>
Sat, 26 Oct 2013 12:55:24 +0000 (15:55 +0300)
If SSL_CTX_new() fails in tls_init(), the per-SSL app-data allocation
could have been leaked when multiple TLS instances are allocated.

Signed-hostap: Jouni Malinen <j@w1.fi>

src/crypto/tls_openssl.c

index 3df2bd2ca60f9e5fa6ab0e843e35e7d2629affb9..95c674a45de7d53fe00997b5ebe6c00d0f14c2aa 100644 (file)
@@ -784,11 +784,13 @@ void * tls_init(const struct tls_config *conf)
        ssl = SSL_CTX_new(TLSv1_method());
        if (ssl == NULL) {
                tls_openssl_ref_count--;
+#ifdef OPENSSL_SUPPORTS_CTX_APP_DATA
+               if (context != tls_global)
+                       os_free(context);
+#endif /* OPENSSL_SUPPORTS_CTX_APP_DATA */
                if (tls_openssl_ref_count == 0) {
                        os_free(tls_global);
                        tls_global = NULL;
-               } else if (context != tls_global) {
-                       os_free(context);
                }
                return NULL;
        }