Skip to content

Commit 4bd7b4d

Browse files
Free String memory on assign of "" or clear()
Fixes esp8266#8485 Whenever the empty C string is assigned or the .clear() method called, free any heap allocated with the String.
1 parent f60defc commit 4bd7b4d

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

cores/esp8266/WString.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ String &String::operator =(String &&rval) noexcept {
258258
}
259259

260260
String &String::operator =(const char *cstr) {
261-
if (cstr)
261+
if (cstr && cstr[0])
262262
copy(cstr, strlen(cstr));
263263
else
264264
invalidate();

cores/esp8266/WString.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class String {
8888
return buffer() ? len() : 0;
8989
}
9090
void clear(void) {
91-
setLen(0);
91+
invalidate();
9292
}
9393
bool isEmpty(void) const {
9494
return length() == 0;

0 commit comments

Comments
 (0)