mirror of
https://github.com/me-no-dev/ESPAsyncWebServer.git
synced 2025-08-05 05:34:38 +02:00
Fix memory leak on successive call to setAuthentication
(as reported in https://github.com/tbnobody/OpenDTU/pull/2320)
This commit is contained in:
@@ -717,7 +717,8 @@ class AsyncWebRewrite {
|
||||
|
||||
class AsyncWebHandler : public AsyncMiddlewareChain {
|
||||
protected:
|
||||
ArRequestFilterFunction _filter{nullptr};
|
||||
ArRequestFilterFunction _filter = nullptr;
|
||||
AuthenticationMiddleware* _authMiddleware = nullptr;
|
||||
|
||||
public:
|
||||
AsyncWebHandler() {}
|
||||
|
@@ -28,13 +28,13 @@ AsyncWebHandler& AsyncWebHandler::setFilter(ArRequestFilterFunction fn) {
|
||||
return *this;
|
||||
}
|
||||
AsyncWebHandler& AsyncWebHandler::setAuthentication(const char* username, const char* password) {
|
||||
if (username == nullptr || password == nullptr || strlen(username) == 0 || strlen(password) == 0)
|
||||
return *this;
|
||||
AuthenticationMiddleware* m = new AuthenticationMiddleware();
|
||||
m->setUsername(username);
|
||||
m->setPassword(password);
|
||||
m->_freeOnRemoval = true;
|
||||
addMiddleware(m);
|
||||
if (!_authMiddleware) {
|
||||
_authMiddleware = new AuthenticationMiddleware();
|
||||
_authMiddleware->_freeOnRemoval = true;
|
||||
addMiddleware(_authMiddleware);
|
||||
}
|
||||
_authMiddleware->setUsername(username);
|
||||
_authMiddleware->setPassword(password);
|
||||
return *this;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user