Skip to content

Commit

Permalink
Remove warning about unused fields (#116)
Browse files Browse the repository at this point in the history
more safety checks around malloc and removes unused variable
  • Loading branch information
mathieucarbou authored Aug 8, 2024
1 parent d943d0a commit 1947a18
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/ChunkPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ size_t ChunkPrinter::write(uint8_t c)

size_t ChunkPrinter::write(const uint8_t *buffer, size_t size)
{
esp_err_t err;
size_t written = 0;

while (written < size)
Expand Down
11 changes: 9 additions & 2 deletions src/PsychicFileResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,16 @@ esp_err_t PsychicFileResponse::send()
if (size < FILE_CHUNK_SIZE)
{
uint8_t *buffer = (uint8_t *)malloc(size);
int readSize = _content.readBytes((char *)buffer, size);
if (buffer == NULL)
{
/* Respond with 500 Internal Server Error */
httpd_resp_send_err(this->_request->request(), HTTPD_500_INTERNAL_SERVER_ERROR, "Unable to allocate memory.");
return ESP_FAIL;
}

size_t readSize = _content.readBytes((char *)buffer, size);

this->setContent(buffer, size);
this->setContent(buffer, readSize);
err = PsychicResponse::send();

free(buffer);
Expand Down

0 comments on commit 1947a18

Please sign in to comment.