ustream-ssl: add support for using a fd instead of ustream as backing
[project/ustream-ssl.git] / ustream-openssl.c
index 3d576be1cf9397adf812bc03f1c87fa4096f9678..b080081c172ffc14786ef61b8e5c1e197b4e3003 100644 (file)
@@ -245,13 +245,18 @@ __hidden void __ustream_ssl_context_free(struct ustream_ssl_ctx *ctx)
        free(ctx);
 }
 
-void __ustream_ssl_session_free(void *ssl)
+__hidden void __ustream_ssl_session_free(struct ustream_ssl *us)
 {
-       BIO *bio = SSL_get_wbio(ssl);
-       struct bio_ctx *ctx = BIO_get_data(bio);
+       BIO *bio = SSL_get_wbio(us->ssl);
+       struct bio_ctx *ctx;
 
-       SSL_shutdown(ssl);
-       SSL_free(ssl);
+       SSL_shutdown(us->ssl);
+       SSL_free(us->ssl);
+
+       if (!us->conn)
+               return;
+
+       ctx = BIO_get_data(bio);
        if (ctx) {
                BIO_meth_free(ctx->meth);
                free(ctx);