Skip to content

Commit f80248b

Browse files
Merge pull request #189 from ESP32Async/fix
2 parents 5f5d072 + 7750959 commit f80248b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

examples/ChunkRetryResponse/ChunkRetryResponse.ino

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,34 @@ void setup() {
131131
"/api", HTTP_POST,
132132
[](AsyncWebServerRequest *request) {
133133
// request parsing has finished
134+
String *data = (String *)request->_tempObject;
135+
136+
if (!data) {
137+
request->send(400);
138+
return;
139+
}
134140

135141
// no data ?
136-
if (!((String *)request->_tempObject)->length()) {
142+
if (!data->length()) {
143+
delete data;
144+
request->_tempObject = nullptr;
137145
request->send(400);
138146
return;
139147
}
140148

141149
JsonDocument doc;
142150

143151
// deserialize and check for errors
144-
if (deserializeJson(doc, *(String *)request->_tempObject)) {
152+
if (deserializeJson(doc, *data)) {
153+
delete data;
154+
request->_tempObject = nullptr;
145155
request->send(400);
146156
return;
147157
}
148158

159+
delete data;
160+
request->_tempObject = nullptr;
161+
149162
// start UART com: UART will send the data to the Serial console and wait for the key press
150163
triggerUART = doc["input"].as<const char *>();
151164
key = -1;

0 commit comments

Comments
 (0)