diff options
author | Jack Lloyd <[email protected]> | 2017-09-22 19:18:25 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-09-22 19:18:25 -0400 |
commit | f9051c02b7b1ce4c97a16a218b0cea0439722f4e (patch) | |
tree | 0ffaa210713afe14c4a838a918c8a7774d225eb8 /src/lib/entropy | |
parent | 096d99fe1528195c523ee6ed7b3defb7519140e2 (diff) |
Use RAII, avoid explicit delete
Diffstat (limited to 'src/lib/entropy')
-rw-r--r-- | src/lib/entropy/entropy_src.h | 4 | ||||
-rw-r--r-- | src/lib/entropy/entropy_srcs.cpp | 16 |
2 files changed, 4 insertions, 16 deletions
diff --git a/src/lib/entropy/entropy_src.h b/src/lib/entropy/entropy_src.h index 3b91847d8..33fdbc3e6 100644 --- a/src/lib/entropy/entropy_src.h +++ b/src/lib/entropy/entropy_src.h @@ -68,10 +68,8 @@ class BOTAN_PUBLIC_API(2,0) Entropy_Sources final Entropy_Sources() {} explicit Entropy_Sources(const std::vector<std::string>& sources); - - ~Entropy_Sources(); private: - std::vector<Entropy_Source*> m_srcs; + std::vector<std::unique_ptr<Entropy_Source>> m_srcs; }; } diff --git a/src/lib/entropy/entropy_srcs.cpp b/src/lib/entropy/entropy_srcs.cpp index 69e593fb9..c05ff9495 100644 --- a/src/lib/entropy/entropy_srcs.cpp +++ b/src/lib/entropy/entropy_srcs.cpp @@ -130,7 +130,7 @@ void Entropy_Sources::add_source(std::unique_ptr<Entropy_Source> src) { if(src.get()) { - m_srcs.push_back(src.release()); + m_srcs.push_back(std::move(src)); } } @@ -154,9 +154,9 @@ size_t Entropy_Sources::poll(RandomNumberGenerator& rng, size_t bits_collected = 0; - for(Entropy_Source* src : m_srcs) + for(size_t i = 0; i != m_srcs.size(); ++i) { - bits_collected += src->poll(rng); + bits_collected += m_srcs[i]->poll(rng); if (bits_collected >= poll_bits || clock::now() > deadline) break; @@ -186,16 +186,6 @@ Entropy_Sources::Entropy_Sources(const std::vector<std::string>& sources) } } -Entropy_Sources::~Entropy_Sources() - { - for(size_t i = 0; i != m_srcs.size(); ++i) - { - delete m_srcs[i]; - m_srcs[i] = nullptr; - } - m_srcs.clear(); - } - Entropy_Sources& Entropy_Sources::global_sources() { static Entropy_Sources global_entropy_sources(BOTAN_ENTROPY_DEFAULT_SOURCES); |