From 39838386943f4f392f5b3a55481f691787360473 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 7 Apr 2015 16:02:07 -0400 Subject: [PATCH] use unique_ptr for ElGamalEncryption --- Identity.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Identity.h b/Identity.h index b5109c35..16c9423e 100644 --- a/Identity.h +++ b/Identity.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "base64.h" #include "ElGamal.h" #include "Signature.h" @@ -219,23 +220,23 @@ namespace data { public: - RoutingDestination (): m_ElGamalEncryption (nullptr) {}; - virtual ~RoutingDestination () { delete m_ElGamalEncryption; }; + RoutingDestination () {}; + virtual ~RoutingDestination () {}; virtual const IdentHash& GetIdentHash () const = 0; virtual const uint8_t * GetEncryptionPublicKey () const = 0; virtual bool IsDestination () const = 0; // for garlic - const i2p::crypto::ElGamalEncryption * GetElGamalEncryption () const + std::unique_ptr& GetElGamalEncryption () const { if (!m_ElGamalEncryption) - m_ElGamalEncryption = new i2p::crypto::ElGamalEncryption (GetEncryptionPublicKey ()); + m_ElGamalEncryption.reset (new i2p::crypto::ElGamalEncryption (GetEncryptionPublicKey ())); return m_ElGamalEncryption; } private: - mutable i2p::crypto::ElGamalEncryption * m_ElGamalEncryption; // use lazy initialization + mutable std::unique_ptr m_ElGamalEncryption; // use lazy initialization }; class LocalDestination