Increment SSL_CTX's reference count in Ssl::get_ssl_context()
Without this, whenever the returned SslContext is released, the refcount of the underlying SSL_CTX will decrease and it will be freed too soon
This commit is contained in:
parent
7835ea1c90
commit
6850c810d3
|
|
@ -69,4 +69,6 @@ extern {
|
||||||
pub fn SSL_CTX_set_tlsext_servername_callback(ssl: *mut SSL_CTX, callback: Option<extern fn()>);
|
pub fn SSL_CTX_set_tlsext_servername_callback(ssl: *mut SSL_CTX, callback: Option<extern fn()>);
|
||||||
#[link_name = "SSL_CTX_set_tlsext_servername_arg_shim"]
|
#[link_name = "SSL_CTX_set_tlsext_servername_arg_shim"]
|
||||||
pub fn SSL_CTX_set_tlsext_servername_arg(ssl: *mut SSL_CTX, arg: *const c_void);
|
pub fn SSL_CTX_set_tlsext_servername_arg(ssl: *mut SSL_CTX, arg: *const c_void);
|
||||||
|
#[link_name = "SSL_CTX_increment_refcount_shim"]
|
||||||
|
pub fn SSL_CTX_increment_refcount(ssl: *mut SSL_CTX) -> c_long;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,11 @@ long SSL_CTX_set_tlsext_servername_arg_shim(SSL_CTX *ctx, void* arg) {
|
||||||
return SSL_CTX_set_tlsext_servername_arg(ctx, arg);
|
return SSL_CTX_set_tlsext_servername_arg(ctx, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long SSL_CTX_increment_refcount_shim(SSL_CTX *ctx) {
|
||||||
|
int i = CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
#if OPENSSL_VERSION_NUMBER >= 0x10002000L
|
#if OPENSSL_VERSION_NUMBER >= 0x10002000L
|
||||||
int SSL_CTX_set_ecdh_auto_shim(SSL_CTX *ctx, int onoff) {
|
int SSL_CTX_set_ecdh_auto_shim(SSL_CTX *ctx, int onoff) {
|
||||||
return SSL_CTX_set_ecdh_auto(ctx, onoff);
|
return SSL_CTX_set_ecdh_auto(ctx, onoff);
|
||||||
|
|
|
||||||
|
|
@ -995,6 +995,7 @@ impl Ssl {
|
||||||
/// obtain the context corresponding to the current connection
|
/// obtain the context corresponding to the current connection
|
||||||
pub fn get_ssl_context(&self) -> SslContext {
|
pub fn get_ssl_context(&self) -> SslContext {
|
||||||
let ssl_ctx = unsafe { ffi::SSL_get_SSL_CTX(self.ssl) };
|
let ssl_ctx = unsafe { ffi::SSL_get_SSL_CTX(self.ssl) };
|
||||||
|
let count = unsafe { ffi_extras::SSL_CTX_increment_refcount(ssl_ctx) };
|
||||||
SslContext { ctx: ssl_ctx }
|
SslContext { ctx: ssl_ctx }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue