1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-12 01:53:07 +03:00

replace new by new (std::nothrow), remove arduino_new

This commit is contained in:
david gauchard
2020-08-17 18:15:45 +02:00
parent 5b3d290de8
commit 6925982284
45 changed files with 207 additions and 167 deletions

View File

@ -126,12 +126,12 @@ bool ESP8266WebServerTemplate<ServerType>::authenticate(const char * username, c
authReq = authReq.substring(6);
authReq.trim();
char toencodeLen = strlen(username)+strlen(password)+1;
char *toencode = new char[toencodeLen + 1];
char *toencode = new (std::nothrow) char[toencodeLen + 1];
if(toencode == NULL){
authReq = "";
return false;
}
char *encoded = new char[base64_encode_expected_len(toencodeLen)+1];
char *encoded = new (std::nothrow) char[base64_encode_expected_len(toencodeLen)+1];
if(encoded == NULL){
authReq = "";
delete[] toencode;
@ -266,7 +266,7 @@ void ESP8266WebServerTemplate<ServerType>::on(const Uri &uri, HTTPMethod method,
template <typename ServerType>
void ESP8266WebServerTemplate<ServerType>::on(const Uri &uri, HTTPMethod method, ESP8266WebServerTemplate<ServerType>::THandlerFunction fn, ESP8266WebServerTemplate<ServerType>::THandlerFunction ufn) {
_addRequestHandler(new FunctionRequestHandler<ServerType>(fn, ufn, uri, method));
_addRequestHandler(new (std::nothrow) FunctionRequestHandler<ServerType>(fn, ufn, uri, method));
}
template <typename ServerType>
@ -288,7 +288,7 @@ void ESP8266WebServerTemplate<ServerType>::_addRequestHandler(RequestHandlerType
template <typename ServerType>
void ESP8266WebServerTemplate<ServerType>::serveStatic(const char* uri, FS& fs, const char* path, const char* cache_header) {
_addRequestHandler(new StaticRequestHandler<ServerType>(fs, path, uri, cache_header));
_addRequestHandler(new (std::nothrow) StaticRequestHandler<ServerType>(fs, path, uri, cache_header));
}
template <typename ServerType>
@ -645,7 +645,9 @@ void ESP8266WebServerTemplate<ServerType>::collectHeaders(const char* headerKeys
_headerKeysCount = headerKeysCount + 1;
if (_currentHeaders)
delete[]_currentHeaders;
_currentHeaders = new RequestArgument[_headerKeysCount];
_currentHeaders = new (std::nothrow) RequestArgument[_headerKeysCount];
if (_currentHeaders == nullptr)
return;
_currentHeaders[0].key = FPSTR(AUTHORIZATION_HEADER);
for (int i = 1; i < _headerKeysCount; i++){
_currentHeaders[i].key = headerKeys[i-1];

View File

@ -283,7 +283,9 @@ void ESP8266WebServerTemplate<ServerType>::_parseArguments(const String& data) {
_currentArgCount = _parseArgumentsPrivate(data, nullArgHandler());
// allocate one more, this is needed because {"plain": plainBuf} is always added
_currentArgs = new RequestArgument[_currentArgCount + 1];
_currentArgs = new (std::nothrow) RequestArgument[_currentArgCount + 1];
if (_currentArgs == nullptr)
return;
(void)_parseArgumentsPrivate(data, storeArgHandler<ServerType>());
}
@ -370,7 +372,11 @@ bool ESP8266WebServerTemplate<ServerType>::_parseForm(ClientType& client, const
//start reading the form
if (line == ("--"+boundary)){
if(_postArgs) delete[] _postArgs;
_postArgs = new RequestArgument[WEBSERVER_MAX_POST_ARGS];
_postArgs = new (std::nothrow) RequestArgument[WEBSERVER_MAX_POST_ARGS];
if (_postArgs == nullptr) {
DBGWS("Parse form: oom\n");
return false;
}
_postArgsLen = 0;
while(1){
String argName;
@ -428,7 +434,11 @@ bool ESP8266WebServerTemplate<ServerType>::_parseForm(ClientType& client, const
break;
}
} else {
_currentUpload.reset(new HTTPUpload());
_currentUpload.reset(new (std::nothrow) HTTPUpload());
if (_currentUpload == nullptr) {
DBGWS("Parse form: oom\n");
return false;
}
_currentUpload->status = UPLOAD_FILE_START;
_currentUpload->name = argName;
_currentUpload->filename = argFilename;
@ -521,7 +531,9 @@ readfile:
arg.value = _currentArgs[iarg].value;
}
if (_currentArgs) delete[] _currentArgs;
_currentArgs = new RequestArgument[_postArgsLen];
_currentArgs = new (std::nothrow) RequestArgument[_postArgsLen];
if (_currentArgs == nullptr)
return false;
for (iarg = 0; iarg < _postArgsLen; iarg++){
RequestArgument& arg = _currentArgs[iarg];
arg.key = _postArgs[iarg].key;

View File

@ -16,7 +16,7 @@ class Uri {
virtual ~Uri() {}
virtual Uri* clone() const {
return new Uri(_uri);
return new (std::nothrow) Uri(_uri);
};
virtual bool canHandle(const String &requestUri, __attribute__((unused)) std::vector<String> &pathArgs) {

View File

@ -10,7 +10,7 @@ class UriBraces : public Uri {
explicit UriBraces(const String &uri) : Uri(uri) {};
Uri* clone() const override final {
return new UriBraces(_uri);
return new (std::nothrow) UriBraces(_uri);
};
bool canHandle(const String &requestUri, std::vector<String> &pathArgs) override final {

View File

@ -11,7 +11,7 @@ class UriGlob : public Uri {
explicit UriGlob(const String &uri) : Uri(uri) {};
Uri* clone() const override final {
return new UriGlob(_uri);
return new (std::nothrow) UriGlob(_uri);
};
bool canHandle(const String &requestUri, __attribute__((unused)) std::vector<String> &pathArgs) override final {

View File

@ -25,7 +25,7 @@ class UriRegex : public Uri {
}
Uri* clone() const override final {
return new UriRegex(_uri);
return new (std::nothrow) UriRegex(_uri);
};
bool canHandle(const String &requestUri, std::vector<String> &pathArgs) override final {