From 02e98f54f4268c39dcacd8cecf61aa079315665b Mon Sep 17 00:00:00 2001 From: Sven Steckmann Date: Thu, 17 Oct 2019 22:32:27 +0200 Subject: [PATCH] Remove error prone handling of direct calling destructors. A destructor should never be directly called. But this is a good position to use unique_ptr for memory management. --- src/AutoConnect.cpp | 9 +++------ src/AutoConnect.h | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/AutoConnect.cpp b/src/AutoConnect.cpp index 4de87d3..8611d69 100644 --- a/src/AutoConnect.cpp +++ b/src/AutoConnect.cpp @@ -360,11 +360,8 @@ void AutoConnect::home(const String& uri) { * Stops AutoConnect captive portal service. */ void AutoConnect::end(void) { - if (_responsePage != nullptr) { - _responsePage->~PageBuilder(); - delete _responsePage; - _responsePage = nullptr; - } + _responsePage.reset(); + if (_currentPageElement != nullptr) { _currentPageElement->~PageElement(); _currentPageElement = nullptr; @@ -436,7 +433,7 @@ void AutoConnect::_startWebServer(void) { _webServer->onNotFound(std::bind(&AutoConnect::_handleNotFound, this)); // here, Prepare PageBuilders for captive portal if (!_responsePage) { - _responsePage = new PageBuilder(); + _responsePage.reset( new PageBuilder() ); _responsePage->exitCanHandle(std::bind(&AutoConnect::_classifyHandle, this, std::placeholders::_1, std::placeholders::_2)); _responsePage->onUpload(std::bind(&AutoConnect::_handleUpload, this, std::placeholders::_1, std::placeholders::_2)); _responsePage->insert(*_webServer); diff --git a/src/AutoConnect.h b/src/AutoConnect.h index afd0d9b..5d608fb 100644 --- a/src/AutoConnect.h +++ b/src/AutoConnect.h @@ -274,7 +274,7 @@ class AutoConnect { * Every time a GET/POST HTTP request occurs, an AutoConnect * menu page corresponding to the URI is generated. */ - PageBuilder* _responsePage = nullptr; + std::unique_ptr _responsePage; PageElement* _currentPageElement = nullptr; /** Extended pages made up with AutoConnectAux */