From e46ef8a98b28c72eb46102cb0f20296ca212a29a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20B=C3=B6ker?= Date: Sat, 17 Feb 2024 22:05:37 +0100 Subject: [PATCH] Fix segfaults when double closing Do so by adding simple (non concurrency safe) guards. --- lib/OpenSSL.rakumod | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/OpenSSL.rakumod b/lib/OpenSSL.rakumod index 7ea84a2..d133c3a 100644 --- a/lib/OpenSSL.rakumod +++ b/lib/OpenSSL.rakumod @@ -290,18 +290,26 @@ method check-private-key { } method shutdown { - OpenSSL::SSL::SSL_shutdown($.ssl); + with $!ssl { + OpenSSL::SSL::SSL_shutdown($!ssl); + } } method ctx-free { - OpenSSL::Ctx::SSL_CTX_free($!ctx); + with $!ctx { + OpenSSL::Ctx::SSL_CTX_free($!ctx); + $!ctx = Nil; + } } method ssl-free { - OpenSSL::SSL::SSL_free($!ssl); - if $.using-bio { - # $.internal-bio is freed by the SSL_free call - OpenSSL::Bio::BIO_free($.net-bio); + with $!ssl { + OpenSSL::SSL::SSL_free($!ssl); + if $.using-bio { + # $.internal-bio is freed by the SSL_free call + OpenSSL::Bio::BIO_free($.net-bio); + } + $!ssl = Nil; } }