Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Side by Side Diff: crypto/rsa_private_key_openssl.cc

Issue 392653005: Fix memory leaks when calling EVP_PKEY_get1_RSA. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | crypto/signature_creator_openssl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "crypto/rsa_private_key.h" 5 #include "crypto/rsa_private_key.h"
6 6
7 #include <openssl/evp.h> 7 #include <openssl/evp.h>
8 #include <openssl/pkcs12.h> 8 #include <openssl/pkcs12.h>
9 #include <openssl/rsa.h> 9 #include <openssl/rsa.h>
10 10
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 : key_(NULL) { 100 : key_(NULL) {
101 } 101 }
102 102
103 RSAPrivateKey::~RSAPrivateKey() { 103 RSAPrivateKey::~RSAPrivateKey() {
104 if (key_) 104 if (key_)
105 EVP_PKEY_free(key_); 105 EVP_PKEY_free(key_);
106 } 106 }
107 107
108 RSAPrivateKey* RSAPrivateKey::Copy() const { 108 RSAPrivateKey* RSAPrivateKey::Copy() const {
109 scoped_ptr<RSAPrivateKey> copy(new RSAPrivateKey()); 109 scoped_ptr<RSAPrivateKey> copy(new RSAPrivateKey());
110 RSA* rsa = EVP_PKEY_get1_RSA(key_); 110 ScopedRSA rsa(EVP_PKEY_get1_RSA(key_));
111 if (!rsa) 111 if (!rsa)
112 return NULL; 112 return NULL;
113 copy->key_ = EVP_PKEY_new(); 113 copy->key_ = EVP_PKEY_new();
114 if (!EVP_PKEY_set1_RSA(copy->key_, rsa)) 114 if (!EVP_PKEY_set1_RSA(copy->key_, rsa.get()))
115 return NULL; 115 return NULL;
116 return copy.release(); 116 return copy.release();
117 } 117 }
118 118
119 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) const { 119 bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) const {
120 return ExportKey(key_, i2d_PKCS8PrivateKeyInfo_bio, output); 120 return ExportKey(key_, i2d_PKCS8PrivateKeyInfo_bio, output);
121 } 121 }
122 122
123 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) const { 123 bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) const {
124 return ExportKey(key_, i2d_PUBKEY_bio, output); 124 return ExportKey(key_, i2d_PUBKEY_bio, output);
125 } 125 }
126 126
127 } // namespace crypto 127 } // namespace crypto
OLDNEW
« no previous file with comments | « no previous file | crypto/signature_creator_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698