diff options
author | davidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-14 21:01:52 +0000 |
---|---|---|
committer | davidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-14 21:01:52 +0000 |
commit | 27410402488b0b9efc500aea1b0193e48466fb72 (patch) | |
tree | 5700a2589ebeeadec70f75b2b9a5d25dce7feaaf /crypto | |
parent | 62bd6b196dd3e389223ab2b963e3237017ae631c (diff) | |
download | chromium_src-27410402488b0b9efc500aea1b0193e48466fb72.zip chromium_src-27410402488b0b9efc500aea1b0193e48466fb72.tar.gz chromium_src-27410402488b0b9efc500aea1b0193e48466fb72.tar.bz2 |
Fix memory leaks when calling EVP_PKEY_get1_RSA.
EVP_PKEY_get1_RSA passes the caller a reference that needs to be released
afterwards.
BUG=393659
Review URL: https://codereview.chromium.org/392653005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283020 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/rsa_private_key_openssl.cc | 4 | ||||
-rw-r--r-- | crypto/signature_creator_openssl.cc | 7 |
2 files changed, 6 insertions, 5 deletions
diff --git a/crypto/rsa_private_key_openssl.cc b/crypto/rsa_private_key_openssl.cc index bd00a73..e3cf04c 100644 --- a/crypto/rsa_private_key_openssl.cc +++ b/crypto/rsa_private_key_openssl.cc @@ -107,11 +107,11 @@ RSAPrivateKey::~RSAPrivateKey() { RSAPrivateKey* RSAPrivateKey::Copy() const { scoped_ptr<RSAPrivateKey> copy(new RSAPrivateKey()); - RSA* rsa = EVP_PKEY_get1_RSA(key_); + ScopedRSA rsa(EVP_PKEY_get1_RSA(key_)); if (!rsa) return NULL; copy->key_ = EVP_PKEY_new(); - if (!EVP_PKEY_set1_RSA(copy->key_, rsa)) + if (!EVP_PKEY_set1_RSA(copy->key_, rsa.get())) return NULL; return copy.release(); } diff --git a/crypto/signature_creator_openssl.cc b/crypto/signature_creator_openssl.cc index e46d3d0..3c8f532 100644 --- a/crypto/signature_creator_openssl.cc +++ b/crypto/signature_creator_openssl.cc @@ -12,6 +12,7 @@ #include "base/stl_util.h" #include "crypto/openssl_util.h" #include "crypto/rsa_private_key.h" +#include "crypto/scoped_openssl_types.h" namespace crypto { @@ -30,14 +31,14 @@ bool SignatureCreator::Sign(RSAPrivateKey* key, const uint8* data, int data_len, std::vector<uint8>* signature) { - RSA* rsa_key = EVP_PKEY_get1_RSA(key->key()); + ScopedRSA rsa_key(EVP_PKEY_get1_RSA(key->key())); if (!rsa_key) return false; - signature->resize(RSA_size(rsa_key)); + signature->resize(RSA_size(rsa_key.get())); unsigned int len = 0; bool success = RSA_sign(NID_sha1, data, data_len, vector_as_array(signature), - &len, rsa_key); + &len, rsa_key.get()); if (!success) { signature->clear(); return false; |