diff --git a/src/AutoConnect.cpp b/src/AutoConnect.cpp index 8611d69..c5c946c 100644 --- a/src/AutoConnect.cpp +++ b/src/AutoConnect.cpp @@ -361,11 +361,7 @@ void AutoConnect::home(const String& uri) { */ void AutoConnect::end(void) { _responsePage.reset(); - - if (_currentPageElement != nullptr) { - _currentPageElement->~PageElement(); - _currentPageElement = nullptr; - } + _currentPageElement.reset(); _stopPortal(); _dnsServer.reset(); @@ -912,12 +908,13 @@ bool AutoConnect::_classifyHandle(HTTPMethod method, String uri) { _purgePages(); // Create the page dynamically - if ((_currentPageElement = _setupPage(uri)) == nullptr) - if (_aux) { - // Requested URL is not a normal page, exploring AUX pages - _currentPageElement = _aux->_setupPage(uri); - } - if (_currentPageElement != nullptr) { + _currentPageElement.reset( _setupPage(uri) ); + if (!_currentPageElement && _aux) { + // Requested URL is not a normal page, exploring AUX pages + _currentPageElement.reset(_aux->_setupPage(uri)); + } + + if (_currentPageElement) { AC_DBG_DUMB(",generated:%s", uri.c_str()); _uri = uri; _responsePage->addElement(*_currentPageElement); @@ -947,9 +944,8 @@ void AutoConnect::_handleUpload(const String& requestUri, const HTTPUpload& uplo */ void AutoConnect::_purgePages(void) { _responsePage->clearElement(); - if (_currentPageElement != nullptr) { - delete _currentPageElement; - _currentPageElement = nullptr; + if (_currentPageElement) { + _currentPageElement.reset(); _uri = String(""); } } diff --git a/src/AutoConnect.h b/src/AutoConnect.h index 5d608fb..f0f8a98 100644 --- a/src/AutoConnect.h +++ b/src/AutoConnect.h @@ -275,7 +275,7 @@ class AutoConnect { * menu page corresponding to the URI is generated. */ std::unique_ptr _responsePage; - PageElement* _currentPageElement = nullptr; + std::unique_ptr _currentPageElement; /** Extended pages made up with AutoConnectAux */ AutoConnectAux* _aux = nullptr; /**< A top of registered AutoConnectAux */