From e7d0e69c74f1cb77099ec899e4ccebf6c33d1bf5 Mon Sep 17 00:00:00 2001 From: Adrian Budau Date: Wed, 26 Feb 2020 16:23:46 +0200 Subject: [PATCH] Fix the memory leak in `X509Builder::append_extension`. Also add an alternative method that takes a `X509ExtensionRef`. --- openssl/src/x509/mod.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs index 5c750d60..45d09f71 100644 --- a/openssl/src/x509/mod.rs +++ b/openssl/src/x509/mod.rs @@ -342,10 +342,20 @@ impl X509Builder { } /// Adds an X509 extension value to the certificate. + /// + /// This works just as `append_extension` except it takes ownership of the `X509Extension`. pub fn append_extension(&mut self, extension: X509Extension) -> Result<(), ErrorStack> { + self.append_extension2(&extension) + } + + /// Adds an X509 extension value to the certificate. + /// + /// This corresponds to [`X509_add_ext`]. + /// + /// [`X509_add_ext`]: https://www.openssl.org/docs/man1.1.0/man3/X509_get_ext.html + pub fn append_extension2(&mut self, extension: &X509ExtensionRef) -> Result<(), ErrorStack> { unsafe { cvt(ffi::X509_add_ext(self.0.as_ptr(), extension.as_ptr(), -1))?; - mem::forget(extension); Ok(()) } }