diff options
| author | Steven Fackler <[email protected]> | 2016-08-14 11:16:53 -0700 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2016-08-14 11:16:53 -0700 |
| commit | e5299fd7c9661579d6de30a5be5b032a90203c95 (patch) | |
| tree | 22d1370eaf79be59ea97a764901324310290a060 /openssl/src | |
| parent | PKCS #12 support (diff) | |
| download | rust-openssl-e5299fd7c9661579d6de30a5be5b032a90203c95.tar.xz rust-openssl-e5299fd7c9661579d6de30a5be5b032a90203c95.zip | |
Fix memory leak in general name stack
Diffstat (limited to 'openssl/src')
| -rw-r--r-- | openssl/src/x509/mod.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs index 4943f7a9..fb6c2aaa 100644 --- a/openssl/src/x509/mod.rs +++ b/openssl/src/x509/mod.rs @@ -408,7 +408,7 @@ impl<'a> X509Ref<'a> { } Some(GeneralNames { - stack: stack as *const _, + stack: stack as *mut _, m: PhantomData, }) } @@ -735,12 +735,23 @@ make_validation_error!(X509_V_OK, X509ApplicationVerification = X509_V_ERR_APPLICATION_VERIFICATION, ); +// FIXME remove lifetime param for 0.9 /// A collection of OpenSSL `GENERAL_NAME`s. pub struct GeneralNames<'a> { - stack: *const ffi::stack_st_GENERAL_NAME, + stack: *mut ffi::stack_st_GENERAL_NAME, m: PhantomData<&'a ()>, } +impl<'a> Drop for GeneralNames<'a> { + fn drop(&mut self) { + unsafe { + let free: unsafe extern "C" fn(*mut ffi::GENERAL_NAME) = ffi::GENERAL_NAME_free; + let free: unsafe extern "C" fn(*mut c_void) = mem::transmute(free); + ffi::sk_pop_free(&mut (*self.stack).stack, Some(free)); + } + } +} + impl<'a> GeneralNames<'a> { /// Returns the number of `GeneralName`s in this structure. pub fn len(&self) -> usize { |