aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorlloyd <[email protected]>2015-03-08 14:15:34 +0000
committerlloyd <[email protected]>2015-03-08 14:15:34 +0000
commitf0ccd62149e466d4fbf1fb2c57227c4d3cee190c (patch)
tree1db968e1b23c96dba5e830247684a2a90459b084 /src/tests
parent6fcdb56ee42078172d44529d55a57bf377f5ae53 (diff)
Fix memory leak in TLS tests. Remove last few remaining uses of auto_ptr.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/test_pubkey.cpp4
-rw-r--r--src/tests/unit_tls.cpp22
2 files changed, 14 insertions, 12 deletions
diff --git a/src/tests/test_pubkey.cpp b/src/tests/test_pubkey.cpp
index 9f46e5398..a05760fd2 100644
--- a/src/tests/test_pubkey.cpp
+++ b/src/tests/test_pubkey.cpp
@@ -93,7 +93,7 @@ size_t validate_save_and_load(const Private_Key* priv_key,
try
{
DataSource_Memory input_pub(pub_pem);
- std::auto_ptr<Public_Key> restored_pub(X509::load_key(input_pub));
+ std::unique_ptr<Public_Key> restored_pub(X509::load_key(input_pub));
if(!restored_pub.get())
{
@@ -119,7 +119,7 @@ size_t validate_save_and_load(const Private_Key* priv_key,
try
{
DataSource_Memory input_priv(priv_pem);
- std::auto_ptr<Private_Key> restored_priv(
+ std::unique_ptr<Private_Key> restored_priv(
PKCS8::load_key(input_priv, rng));
if(!restored_priv.get())
diff --git a/src/tests/unit_tls.cpp b/src/tests/unit_tls.cpp
index 60b7297a1..aeab7cd4e 100644
--- a/src/tests/unit_tls.cpp
+++ b/src/tests/unit_tls.cpp
@@ -35,16 +35,18 @@ class Credentials_Manager_Test : public Botan::Credentials_Manager
m_ca_cert(ca_cert),
m_key(server_key)
{
- auto store = new Certificate_Store_In_Memory;
- store->add_certificate(m_ca_cert);
- m_stores.push_back(store);
+ std::unique_ptr<Certificate_Store> store(new Certificate_Store_In_Memory(m_ca_cert));
+ m_stores.push_back(std::move(store));
}
std::vector<Certificate_Store*>
trusted_certificate_authorities(const std::string&,
const std::string&) override
{
- return m_stores;
+ std::vector<Certificate_Store*> v;
+ for(auto&& store : m_stores)
+ v.push_back(store.get());
+ return v;
}
std::vector<X509_Certificate> cert_chain(
@@ -92,17 +94,17 @@ class Credentials_Manager_Test : public Botan::Credentials_Manager
const std::string&,
const std::string&) override
{
- return m_key;
+ return m_key.get();
}
public:
X509_Certificate m_server_cert, m_ca_cert;
- Private_Key* m_key;
- std::vector<Certificate_Store*> m_stores;
+ std::unique_ptr<Private_Key> m_key;
+ std::vector<std::unique_ptr<Certificate_Store>> m_stores;
};
Credentials_Manager* create_creds(RandomNumberGenerator& rng)
{
- std::auto_ptr<Private_Key> ca_key(new RSA_PrivateKey(rng, 1024));
+ std::unique_ptr<Private_Key> ca_key(new RSA_PrivateKey(rng, 1024));
X509_Cert_Options ca_opts;
ca_opts.common_name = "Test CA";
@@ -288,13 +290,13 @@ size_t test_tls()
Test_Policy default_policy;
auto& rng = test_rng();
- std::auto_ptr<Credentials_Manager> basic_creds(create_creds(rng));
+ std::unique_ptr<Credentials_Manager> basic_creds(create_creds(rng));
errors += basic_test_handshake(rng, TLS::Protocol_Version::TLS_V10, *basic_creds, default_policy);
errors += basic_test_handshake(rng, TLS::Protocol_Version::TLS_V11, *basic_creds, default_policy);
errors += basic_test_handshake(rng, TLS::Protocol_Version::TLS_V12, *basic_creds, default_policy);
- test_report("TLS", 4, errors);
+ test_report("TLS", 3, errors);
return errors;
}