From 3c6c4a7b3df9082188ec45f3e636440abfc5c563 Mon Sep 17 00:00:00 2001 From: Overmind JIANG Date: Wed, 18 Nov 2015 11:36:34 +0800 Subject: [PATCH] Fix a leak when using `EVP_PKEY_get1_RSA`. `EVP_PKEY_get1_RSA` returns a RSA structure with its reference count increased by 1 and therefore we need to call `RSA_free` after finishing using that value. --- openssl-sys/src/lib.rs | 1 + openssl/src/crypto/pkey.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/openssl-sys/src/lib.rs b/openssl-sys/src/lib.rs index 018f8bca0..239f8d9e8 100644 --- a/openssl-sys/src/lib.rs +++ b/openssl-sys/src/lib.rs @@ -482,6 +482,7 @@ extern "C" { pub fn RAND_bytes(buf: *mut u8, num: c_int) -> c_int; + pub fn RSA_free(rsa: *mut RSA); pub fn RSA_generate_key(modsz: c_int, e: c_ulong, cb: *const c_void, cbarg: *const c_void) -> *mut RSA; pub fn RSA_generate_key_ex(rsa: *mut RSA, bits: c_int, e: *mut BIGNUM, cb: *const c_void) -> c_int; pub fn RSA_private_decrypt(flen: c_int, from: *const u8, to: *mut u8, k: *mut RSA, diff --git a/openssl/src/crypto/pkey.rs b/openssl/src/crypto/pkey.rs index 6ca0aa120..741c67493 100644 --- a/openssl/src/crypto/pkey.rs +++ b/openssl/src/crypto/pkey.rs @@ -120,6 +120,7 @@ impl PKey { let mut s = repeat(0u8).take(len as usize).collect::>(); let r = f(rsa, &s.as_mut_ptr()); + ffi::RSA_free(rsa); s.truncate(r as usize); s -- GitLab