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.
pull/144/head
Sven Steckmann 5 years ago
parent 6d37959fb3
commit 02e98f54f4
  1. 9
      src/AutoConnect.cpp
  2. 2
      src/AutoConnect.h

@ -360,11 +360,8 @@ void AutoConnect::home(const String& uri) {
* Stops AutoConnect captive portal service. * Stops AutoConnect captive portal service.
*/ */
void AutoConnect::end(void) { void AutoConnect::end(void) {
if (_responsePage != nullptr) { _responsePage.reset();
_responsePage->~PageBuilder();
delete _responsePage;
_responsePage = nullptr;
}
if (_currentPageElement != nullptr) { if (_currentPageElement != nullptr) {
_currentPageElement->~PageElement(); _currentPageElement->~PageElement();
_currentPageElement = nullptr; _currentPageElement = nullptr;
@ -436,7 +433,7 @@ void AutoConnect::_startWebServer(void) {
_webServer->onNotFound(std::bind(&AutoConnect::_handleNotFound, this)); _webServer->onNotFound(std::bind(&AutoConnect::_handleNotFound, this));
// here, Prepare PageBuilders for captive portal // here, Prepare PageBuilders for captive portal
if (!_responsePage) { if (!_responsePage) {
_responsePage = new PageBuilder(); _responsePage.reset( new PageBuilder() );
_responsePage->exitCanHandle(std::bind(&AutoConnect::_classifyHandle, this, std::placeholders::_1, std::placeholders::_2)); _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->onUpload(std::bind(&AutoConnect::_handleUpload, this, std::placeholders::_1, std::placeholders::_2));
_responsePage->insert(*_webServer); _responsePage->insert(*_webServer);

@ -274,7 +274,7 @@ class AutoConnect {
* Every time a GET/POST HTTP request occurs, an AutoConnect * Every time a GET/POST HTTP request occurs, an AutoConnect
* menu page corresponding to the URI is generated. * menu page corresponding to the URI is generated.
*/ */
PageBuilder* _responsePage = nullptr; std::unique_ptr<PageBuilder> _responsePage;
PageElement* _currentPageElement = nullptr; PageElement* _currentPageElement = nullptr;
/** Extended pages made up with AutoConnectAux */ /** Extended pages made up with AutoConnectAux */

Loading…
Cancel
Save