Skip to content

Commit 001a129

Browse files
committed
Fix heap node corruption (#428)
1 parent ed1a406 commit 001a129

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

cores/esp8266/WString.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ ICACHE_FLASH_ATTR String::String(double value, unsigned char decimalPlaces) {
118118
}
119119

120120
ICACHE_FLASH_ATTR String::~String() {
121-
os_free(buffer);
121+
free(buffer);
122122
}
123123

124124
// /*********************************************/
@@ -133,7 +133,7 @@ inline void String::init(void) {
133133

134134
void ICACHE_FLASH_ATTR String::invalidate(void) {
135135
if(buffer)
136-
os_free(buffer);
136+
free(buffer);
137137
buffer = NULL;
138138
capacity = len = 0;
139139
}
@@ -150,12 +150,18 @@ unsigned char ICACHE_FLASH_ATTR String::reserve(unsigned int size) {
150150
}
151151

152152
unsigned char ICACHE_FLASH_ATTR String::changeBuffer(unsigned int maxStrLen) {
153-
char *newbuffer = (char *) os_realloc(buffer, maxStrLen + 1);
153+
size_t newSize = (maxStrLen + 16) & (~0xf);
154+
char *newbuffer = (char *) malloc(newSize);
154155
if(newbuffer) {
156+
memset(newbuffer, 0, newSize);
157+
memcpy(newbuffer, buffer, len);
158+
if (buffer)
159+
free(buffer);
160+
capacity = newSize - 1;
155161
buffer = newbuffer;
156-
capacity = maxStrLen;
157162
return 1;
158163
}
164+
buffer = newbuffer;
159165
return 0;
160166
}
161167

@@ -192,7 +198,7 @@ void ICACHE_FLASH_ATTR String::move(String &rhs) {
192198
rhs.len = 0;
193199
return;
194200
} else {
195-
os_free(buffer);
201+
free(buffer);
196202
}
197203
}
198204
buffer = rhs.buffer;

libraries/ESP8266WebServer/src/ESP8266WebServer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ void ESP8266WebServer::_prepareHeader(String& response, int code, const char* co
130130

131131
sendHeader("Content-Type", content_type, true);
132132
if (_contentLength != CONTENT_LENGTH_UNKNOWN && _contentLength != CONTENT_LENGTH_NOT_SET) {
133-
sendHeader("Content-Length", String(_contentLength).c_str());
133+
sendHeader("Content-Length", String(_contentLength));
134134
}
135135
else if (contentLength > 0){
136-
sendHeader("Content-Length", String(contentLength).c_str());
136+
sendHeader("Content-Length", String(contentLength));
137137
}
138138
sendHeader("Connection", "close");
139139
sendHeader("Access-Control-Allow-Origin", "*");

tools/sdk/lib/liblwip.a

4.02 MB
Binary file not shown.

0 commit comments

Comments
 (0)