Skip to content

Commit 71963c6

Browse files
committed
[Memory] Free allocated memory in Strings .clear() does not free it
See: esp8266/Arduino#8485
1 parent f27ac68 commit 71963c6

30 files changed

+46
-46
lines changed

src/_C008.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ bool CPlugin_008(CPlugin::Function function, struct EventStruct *event, String&
4949

5050
case CPlugin::Function::CPLUGIN_PROTOCOL_TEMPLATE:
5151
{
52-
event->String1.clear();
52+
event->String1 = String();
5353
event->String2 = F("demo.php?name=%sysname%&task=%tskname%&valuename=%valname%&value=%value%");
5454
break;
5555
}

src/_C010.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ bool CPlugin_010(CPlugin::Function function, struct EventStruct *event, String&
3535

3636
case CPlugin::Function::CPLUGIN_PROTOCOL_TEMPLATE:
3737
{
38-
event->String1.clear();
38+
event->String1 = String();
3939
event->String2 = F("%sysname%_%tskname%_%valname%=%value%");
4040
break;
4141
}

src/_C016.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ bool CPlugin_016(CPlugin::Function function, struct EventStruct *event, String&
104104

105105
case CPlugin::Function::CPLUGIN_PROTOCOL_TEMPLATE:
106106
{
107-
event->String1.clear();
108-
event->String2.clear();
107+
event->String1 = String();
108+
event->String2 = String();
109109
break;
110110
}
111111

src/_C018.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ struct C018_data_struct {
4848
delete C018_easySerial;
4949
C018_easySerial = nullptr;
5050
}
51-
cacheDevAddr.clear();
52-
cacheHWEUI.clear();
53-
cacheSysVer.clear();
51+
cacheDevAddr = String();
52+
cacheHWEUI = String();
53+
cacheSysVer = String();
5454
autobaud_success = false;
5555
}
5656

@@ -353,15 +353,15 @@ struct C018_data_struct {
353353
}
354354

355355
void updateCacheOnInit() {
356-
cacheDevAddr.clear();
356+
cacheDevAddr = String();
357357

358358
if (isInitialized()) {
359359
if (myLora->getStatus().Joined)
360360
{
361361
cacheDevAddr = myLora->sendRawCommand(F("mac get devaddr"));
362362

363363
if (cacheDevAddr == F("00000000")) {
364-
cacheDevAddr.clear();
364+
cacheDevAddr = String();
365365
}
366366
}
367367
}

src/_P016_IR.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
378378
html_TD();
379379
addCheckBox(getPluginCustomArgName(rowCnt + 1), bitRead(line.CodeFlags, P16_FLAGS_REPEAT));
380380
html_TD();
381-
strCode.clear();
381+
strCode = String();
382382

383383
if (line.Code > 0) {
384384
strCode = uint64ToString(line.Code, 16); // convert code to hex for display
@@ -393,7 +393,7 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
393393
html_TD();
394394
addCheckBox(getPluginCustomArgName(rowCnt + 4), bitRead(line.AlternativeCodeFlags, P16_FLAGS_REPEAT));
395395
html_TD();
396-
strCode.clear();
396+
strCode = String();
397397

398398
if (line.AlternativeCode > 0) {
399399
strCode = uint64ToString(line.AlternativeCode, 16); // convert code to hex for display
@@ -462,7 +462,7 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
462462
for (uint8_t varNr = 0; varNr < P16_Nlines; varNr++) {
463463
tCommandLinesV2 line;
464464

465-
strError.clear();
465+
strError = String();
466466

467467
// Normal Code & flags
468468
line.CodeDecodeType = static_cast<decode_type_t>(getFormItemInt(getPluginCustomArgName(rowCnt + 0)));

src/_P055_Chiming.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ uint8_t Plugin_055_ReadChime(const String& name, String& tokens)
490490
log += fileName;
491491
log += ' ';
492492

493-
tokens.clear();
493+
tokens = String();
494494
fs::File f = tryOpenFile(fileName, "r");
495495
if (f)
496496
{

src/src/Commands/InternalCommands.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ bool do_command_case_check(command_case_data & data,
176176
// The data struct is re-used on each attempt to process an internal command.
177177
// Re-initialize the only two members that may have been altered by a previous call.
178178
data.retval = false;
179-
data.status.clear();
179+
data.status = String();
180180
if (!data.cmd_lc.equals(cmd_test)) {
181181
return false;
182182
}

src/src/DataStructs/Modbus.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ bool Modbus::handle() {
9797
unsigned int RXavailable = 0;
9898

9999
#ifndef BUILD_NO_DEBUG
100-
LogString.clear();
100+
LogString = String();
101101
#endif
102102
int64_t rxValue = 0;
103103

src/src/ESPEasyCore/ESPEasy_Log.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,5 +300,5 @@ void addToLogMove(uint8_t logLevel, String&& string)
300300
Logging.add(logLevel, std::move(string));
301301
}
302302
// Make sure the string may no longer keep up memory
303-
string.clear();
303+
string = String();
304304
}

src/src/Globals/RamTracker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ RamTracker::RamTracker(void) {
8181
writePtr = 0;
8282

8383
for (int i = 0; i < TRACES; i++) {
84-
traces[i].clear();
84+
traces[i] = String();
8585
tracesMemory[i] = 0xffffffff; // init with best case memory values, so they get replaced if memory goes lower
8686
}
8787

@@ -97,7 +97,7 @@ void RamTracker::registerRamState(const String& s) { // store function
9797
int bestCase = bestCaseTrace(); // find best case memory trace
9898

9999
if (ESP.getFreeHeap() < tracesMemory[bestCase]) { // compare to current memory value
100-
traces[bestCase].clear();
100+
traces[bestCase] = String();
101101
readPtr = writePtr + 1; // read out buffer, oldest value first
102102

103103
if (readPtr >= TRACEENTRIES) {
@@ -135,7 +135,7 @@ void RamTracker::getTraceBuffer() {
135135
retval += ' ';
136136
retval += traces[i];
137137
addLogMove(LOG_LEVEL_DEBUG_DEV, retval);
138-
retval.clear();
138+
retval = String();
139139
}
140140
}
141141
#endif // ifndef BUILD_NO_DEBUG

src/src/Helpers/ESPEasy_Storage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ String LoadStringArray(SettingsType::Enum settingsType, int index, String string
676676
#endif
677677

678678
strings[stringCount] = tmpString;
679-
tmpString.clear();
679+
tmpString = String();
680680
tmpString.reserve(estimatedStringSize);
681681
++stringCount;
682682
} else {

src/src/Helpers/ESPEasy_checks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ String ReportOffsetErrorInStruct(const String& structname, size_t offset) {
187187
* Not a member function to be able to use the F-macro
188188
\*********************************************************************************************/
189189
bool SettingsCheck(String& error) {
190-
error.clear();
190+
error = String();
191191
#ifndef LIMIT_BUILD_SIZE
192192
#ifdef esp8266
193193
size_t offset = offsetof(SettingsStruct, ResetFactoryDefaultPreference);

src/src/Helpers/Modbus_RTU.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void ModbusRTU_struct::reset() {
1919
delete easySerial;
2020
easySerial = nullptr;
2121
}
22-
detected_device_description.clear();
22+
detected_device_description = String();
2323

2424
for (int i = 0; i < 8; ++i) {
2525
_sendframe[i] = 0;

src/src/Helpers/StringConverter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ bool GetArgv(const char *string, String& argvString, unsigned int argc, char sep
10921092
int pos_begin, pos_end;
10931093
bool hasArgument = GetArgvBeginEnd(string, argc, pos_begin, pos_end, separator);
10941094

1095-
argvString.clear();
1095+
argvString = String();
10961096

10971097
if (!hasArgument) { return false; }
10981098

src/src/Helpers/StringParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ void transformValue(
278278
}
279279

280280
if (value == F("0")) {
281-
value.clear();
281+
value = String();
282282
} else {
283283
const int valueLength = value.length();
284284

@@ -666,7 +666,7 @@ bool findNextDevValNameInString(const String& input, int& startpos, int& endpos,
666666
format = valueName.substring(hashpos + 1);
667667
valueName = valueName.substring(0, hashpos);
668668
} else {
669-
format.clear();
669+
format = String();
670670
}
671671
deviceName.toLowerCase();
672672
valueName.toLowerCase();

src/src/Helpers/WebServer_commandHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ HandledWebCommand_result handle_command_from_web(EventValueSource::Enum source,
2222

2323
bool handledCmd = false;
2424
bool sendOK = false;
25-
printWebString.clear();
25+
printWebString = String();
2626
printToWeb = false;
2727
printToWebJSON = false;
2828

src/src/Helpers/_CPlugin_Helper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ bool safeReadStringUntil(Stream & input,
5050
const unsigned long timer = start + timeout;
5151
unsigned long backgroundtasks_timer = start + 10;
5252

53-
str.clear();
53+
str = String();
5454

5555
do {
5656
// read character

src/src/PluginStructs/P020_data_struct.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void P020_Task::discardClientIn() {
109109
}
110110

111111
void P020_Task::clearBuffer() {
112-
serial_buffer.clear();
112+
serial_buffer = String();
113113
serial_buffer.reserve(P020_DATAGRAM_MAX_SIZE);
114114
}
115115

src/src/PluginStructs/P044_data_struct.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void P044_Task::clearBuffer() {
122122
maxMessageSize = _min(serial_buffer.length(), P044_DATAGRAM_MAX_SIZE);
123123
}
124124

125-
serial_buffer.clear();
125+
serial_buffer = String();
126126
serial_buffer.reserve(maxMessageSize);
127127
}
128128

src/src/PluginStructs/P073_data_struct.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ void P073_data_struct::NextScroll() {
315315
}
316316

317317
void P073_data_struct::setTextToScroll(const String& text) {
318-
_textToScroll.clear();
318+
_textToScroll = String();
319319

320320
if (!text.isEmpty()) {
321321
const int bufToFill = getBufferLength(displayModel);

src/src/PluginStructs/P082_data_struct.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ bool P082_data_struct::loop() {
167167
// Full sentence received
168168
# ifdef P082_SEND_GPS_TO_LOG
169169
_lastSentence = _currentSentence;
170-
_currentSentence.clear();
170+
_currentSentence = String();
171171
# endif // ifdef P082_SEND_GPS_TO_LOG
172172
completeSentence = true;
173173
} else {

src/src/PluginStructs/P087_data_struct.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ bool P087_data_struct::loop() {
108108

109109
for (size_t i = 0; i < length && valid; ++i) {
110110
if ((sentence_part[i] > 127) || (sentence_part[i] < 32)) {
111-
sentence_part.clear();
111+
sentence_part = String();
112112
++sentences_received_error;
113113
valid = false;
114114
}
@@ -117,7 +117,7 @@ bool P087_data_struct::loop() {
117117
if (valid) {
118118
fullSentenceReceived = true;
119119
last_sentence = sentence_part;
120-
sentence_part.clear();
120+
sentence_part = String();
121121
}
122122
break;
123123
}
@@ -146,7 +146,7 @@ bool P087_data_struct::getSentence(String& string) {
146146
if (string.isEmpty()) {
147147
return false;
148148
}
149-
last_sentence.clear();
149+
last_sentence = String();
150150
return true;
151151
}
152152

src/src/PluginStructs/P094_data_struct.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ bool P094_data_struct::loop() {
114114

115115
for (size_t i = 0; i < length && valid; ++i) {
116116
if ((sentence_part[i] > 127) || (sentence_part[i] < 32)) {
117-
sentence_part.clear();
117+
sentence_part = String();
118118
++sentences_received_error;
119119
valid = false;
120120
}
@@ -151,7 +151,7 @@ const String& P094_data_struct::peekSentence() const {
151151

152152
void P094_data_struct::getSentence(String& string, bool appendSysTime) {
153153
string = std::move(sentence_part);
154-
sentence_part.clear(); // FIXME TD-er: Should not be needed as move already cleared it.
154+
sentence_part = String(); // FIXME TD-er: Should not be needed as move already cleared it.
155155
if (appendSysTime) {
156156
// Unix timestamp = 10 decimals + separator
157157
if (string.reserve(sentence_part.length() + 11)) {

src/src/PluginStructs/P104_data_struct.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ void P104_data_struct::loadSettings() {
313313
# endif // ifdef P104_DEBUG
314314
}
315315

316-
buffer.clear(); // Free some memory
316+
buffer = String(); // Free some memory
317317
}
318318

319319
delete[] settingsBuffer; // Release allocated buffer

src/src/WebServer/ControlPage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void handle_control() {
4141

4242
TXBuffer.endStream();
4343

44-
printWebString.clear();
44+
printWebString = String();
4545
printToWeb = false;
4646
printToWebJSON = false;
4747
}

src/src/WebServer/CustomPage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ bool handle_custom(const String& path) {
153153
line += c;
154154
if (c == '\n') {
155155
addHtml(parseTemplate(line));
156-
line.clear();
156+
line = String();
157157
line.reserve(128);
158158
}
159159
}

src/src/WebServer/RootPage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ void handle_root() {
265265
addHtml(F("<TR><TD colspan='2'>Command Output<BR><textarea readonly rows='10' wrap='on'>"));
266266
addHtml(printWebString);
267267
addHtml(F("</textarea>"));
268-
printWebString.clear();
268+
printWebString = String();
269269
}
270270
}
271271
html_end_table();
@@ -342,7 +342,7 @@ void handle_root() {
342342
html_end_form();
343343
}
344344

345-
printWebString.clear();
345+
printWebString = String();
346346
printToWeb = false;
347347
sendHeadandTail_stdtemplate(_TAIL);
348348
}

src/src/WebServer/ToolsPage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void handle_tools() {
5757
addHtml(F("<TR><TD colspan='2'>Command Output<BR><textarea readonly rows='10' wrap='on'>"));
5858
addHtml(printWebString);
5959
addHtml(F("</textarea>"));
60-
printWebString.clear();
60+
printWebString = String();
6161
}
6262

6363

@@ -177,7 +177,7 @@ void handle_tools() {
177177
html_end_form();
178178
sendHeadandTail_stdtemplate(_TAIL);
179179
TXBuffer.endStream();
180-
printWebString.clear();
180+
printWebString = String();
181181
printToWeb = false;
182182
}
183183

src/src/WebServer/UploadPage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void handle_upload() {
2727
"<form enctype='multipart/form-data' method='post'><p>Upload settings file:<br><input type='file' name='datafile' size='40'></p><div><input class='button link' type='submit' value='Upload'></div><input type='hidden' name='edit' value='1'></form>"));
2828
sendHeadandTail_stdtemplate(true);
2929
TXBuffer.endStream();
30-
printWebString.clear();
30+
printWebString = String();
3131
printToWeb = false;
3232
}
3333

@@ -64,7 +64,7 @@ void handle_upload_post() {
6464
addHtml(F("Upload finished"));
6565
sendHeadandTail_stdtemplate(true);
6666
TXBuffer.endStream();
67-
printWebString.clear();
67+
printWebString = String();
6868
printToWeb = false;
6969
}
7070

src/src/WebServer/WebTemplateParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ bool WebTemplateParser::process(const char c) {
130130
} else if (Tail == contentVarFound) {
131131
processVarName();
132132
}
133-
varName.clear();
133+
varName = String();
134134
}
135135
}
136136
break;

0 commit comments

Comments
 (0)