8000 fix parseArgument by d-a-v · Pull Request #5230 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

fix parseArgument #5230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix memleak
  • Loading branch information
d-a-v committed Oct 16, 2018
commit 9d1e411adb8ba21ebfafe0b8db6411a32f711c5c
22 changes: 10 additions & 12 deletions libraries/ESP8266WebServer/src/Parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,28 +268,29 @@ bool ESP8266WebServer::_collectHeader(const char* headerName, const char* header
}

void ESP8266WebServer::_parseArguments(const String& data) {
int counted = _parseArgumentsPrivate(data, 0);
int counted = _parseArgumentsPrivate(data, -1);
(void)_parseArgumentsPrivate(data, counted);
}

int ESP8266WebServer::_parseArgumentsPrivate(const String& data, int counted) {
// counted==0: parsing only, return counted arguments
// counted!=0: parsing and storing "counted" arguments
// counted<0: parse only, return counted arguments
// counted>=0: allocate counted+1, parse and store "counted" arguments

#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("args: ");
DEBUG_OUTPUT.println(data);
#endif

if (counted > 0) {
if (counted >= 0) {
if (_currentArgs)
delete[] _currentArgs;
_currentArgs = 0;
}
_currentArgCount = counted;

// allocate one more (even if counted==0)
// this is needed because {"plain": plainBuf} is always added
_currentArgs = new RequestArgument[(_currentArgCount = counted) + 1];
// allocate one more (even if counted==0)
// this is needed because {"plain": plainBuf} is always added
_currentArgs = new RequestArgument[_currentArgCount + 1];
}

size_t pos = 0;
int arg_total = 0;
Expand All @@ -316,7 +317,7 @@ int ESP8266WebServer::_parseArgumentsPrivate(const String& data, int counted) {
// handle key/value
if ((int)pos < key_end_pos) {
// do not store or count empty ending key ("url?x=y;")
if (counted > 0) {
if (counted >= 0) {
RequestArgument& arg = _currentArgs[arg_total];
arg.key = urlDecode(data.substring(pos, key_end_pos));
if ((equal_index != -1) && ((equal_index < next_index - 1) || (next_index == -1)))
Expand All @@ -339,9 +340,6 @@ int ESP8266WebServer::_parseArgumentsPrivate(const String& data, int counted) {
DEBUG_OUTPUT.println(arg_total);
#endif

if (counted > 0)
_currentArgCount = arg_total;

return arg_total;
}

Expand Down
0