diff --git a/lib/TTLS/include/Config.h b/lib/TTLS/include/Config.h index 346d80e..db4697d 100644 --- a/lib/TTLS/include/Config.h +++ b/lib/TTLS/include/Config.h @@ -64,6 +64,8 @@ namespace eapserial #include #include +#include + namespace eap { class config_method_ttls : public config_method_tls @@ -90,11 +92,6 @@ namespace eap { /// config_method_ttls(_Inout_ config_method_ttls &&other); - /// - /// Destructs configuration - /// - virtual ~config_method_ttls(); - /// /// Copies configuration /// @@ -158,7 +155,7 @@ namespace eap { virtual eap::type_t get_method_id() const; public: - config *m_inner; ///< Inner authentication configuration + std::unique_ptr m_inner; ///< Inner authentication configuration }; } @@ -169,7 +166,7 @@ namespace eapserial { pack(cursor, (const eap::config_method_tls&)val); if (val.m_inner) { - if (dynamic_cast(val.m_inner)) { + if (dynamic_cast(val.m_inner.get())) { pack(cursor, eap::type_pap); pack(cursor, (const eap::config_method_pap&)*val.m_inner); } else { @@ -185,13 +182,13 @@ namespace eapserial { size_t size_inner; if (val.m_inner) { - if (dynamic_cast(val.m_inner)) { + if (dynamic_cast(val.m_inner.get())) { size_inner = get_pk_size(eap::type_pap) + get_pk_size((const eap::config_method_pap&)*val.m_inner); } else { - size_inner = get_pk_size(eap::type_undefined); assert(0); // Unsupported inner authentication method type. + size_inner = get_pk_size(eap::type_undefined); } } else size_inner = get_pk_size(eap::type_undefined); @@ -206,19 +203,16 @@ namespace eapserial { unpack(cursor, (eap::config_method_tls&)val); - if (val.m_inner) - delete val.m_inner; - eap::type_t eap_type; unpack(cursor, eap_type); switch (eap_type) { case eap::type_pap: - val.m_inner = new eap::config_method_pap(val.m_module); + val.m_inner.reset(new eap::config_method_pap(val.m_module)); unpack(cursor, (eap::config_method_pap&)*val.m_inner); break; default: - val.m_inner = NULL; assert(0); // Unsupported inner authentication method type. + val.m_inner.reset(nullptr); } } } diff --git a/lib/TTLS/src/Config.cpp b/lib/TTLS/src/Config.cpp index bfeff8d..7ca467c 100644 --- a/lib/TTLS/src/Config.cpp +++ b/lib/TTLS/src/Config.cpp @@ -29,31 +29,22 @@ using namespace winstd; ////////////////////////////////////////////////////////////////////// eap::config_method_ttls::config_method_ttls(_In_ module &mod) : - m_inner(NULL), config_method_tls(mod) { } eap::config_method_ttls::config_method_ttls(const _In_ config_method_ttls &other) : - m_inner(other.m_inner ? (config_method*)other.m_inner->clone() : NULL), + m_inner(other.m_inner ? (config_method*)other.m_inner->clone() : nullptr), config_method_tls(other) { } eap::config_method_ttls::config_method_ttls(_Inout_ config_method_ttls &&other) : - m_inner(other.m_inner), + m_inner(std::move(other.m_inner)), config_method_tls(std::move(other)) { - other.m_inner = NULL; -} - - -eap::config_method_ttls::~config_method_ttls() -{ - if (m_inner) - delete m_inner; } @@ -61,8 +52,7 @@ eap::config_method_ttls& eap::config_method_ttls::operator=(const _In_ config_me { if (this != &other) { (config_method_tls&)*this = other; - if (m_inner) delete m_inner; - m_inner = other.m_inner ? (config_method*)other.m_inner->clone() : NULL; + m_inner.reset(other.m_inner ? (config_method*)other.m_inner->clone() : nullptr); } return *this; @@ -73,9 +63,7 @@ eap::config_method_ttls& eap::config_method_ttls::operator=(_Inout_ config_metho { if (this != &other) { (config_method_tls&&)*this = std::move(other); - if (m_inner) delete m_inner; - m_inner = other.m_inner; - other.m_inner = NULL; + m_inner = std::move(other.m_inner); } return *this; @@ -107,7 +95,7 @@ bool eap::config_method_ttls::save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode return false; } - if (dynamic_cast(m_inner)) { + if (dynamic_cast(m_inner.get())) { // / if ((dwResult = eapxml::put_element_value(pDoc, pXmlElInnerAuthenticationMethod, bstr(L"NonEAPAuthMethod"), bstrNamespace, bstr(L"PAP"))) != ERROR_SUCCESS) { *ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating element.")); @@ -158,8 +146,7 @@ bool eap::config_method_ttls::load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERRO { // PAP m_module.log_config((xpath + L"/NonEAPAuthMethod").c_str(), L"PAP"); - assert(!m_inner); - m_inner = new eap::config_method_pap(m_module); + m_inner.reset(new eap::config_method_pap(m_module)); if (!m_inner->load(pXmlElInnerAuthenticationMethod, ppEapError)) return false; } else { diff --git a/lib/TTLS_UI/include/TTLS_UI.h b/lib/TTLS_UI/include/TTLS_UI.h index 86761bf..e5417e2 100644 --- a/lib/TTLS_UI/include/TTLS_UI.h +++ b/lib/TTLS_UI/include/TTLS_UI.h @@ -213,7 +213,7 @@ protected: m_inner_type->GetChoiceCtrl()->Enable(false); } - eap::config_method_pap *cfg_pap = dynamic_cast(m_cfg.m_inner); + eap::config_method_pap *cfg_pap = dynamic_cast(m_cfg.m_inner.get()); if (cfg_pap) { m_cfg_pap = *cfg_pap; m_inner_type->SetSelection(0); // 0=PAP @@ -234,8 +234,7 @@ protected: // This is not a provider-locked configuration. Save the data. switch (m_inner_type->GetSelection()) { case 0: // 0=PAP - delete m_cfg.m_inner; - m_cfg.m_inner = new eap::config_method_pap(m_cfg_pap); + m_cfg.m_inner.reset(new eap::config_method_pap(m_cfg_pap)); break; default: