fix free() too early (#17710)

This commit is contained in:
Barbudor 2023-01-15 16:20:35 +01:00 committed by GitHub
parent e0b17af307
commit 2d1d49504b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -925,7 +925,7 @@ uint8_t UfsDownloadFile(char *file) {
UfsData.download_busy = true; UfsData.download_busy = true;
char *path = (char*)malloc(128); char *path = (char*)malloc(128);
strcpy(path,file); strcpy(path,file);
BaseType_t ret = xTaskCreatePinnedToCore(donload_task, "DT", 6000, (void*)path, 3, nullptr, 1); BaseType_t ret = xTaskCreatePinnedToCore(download_task, "DT", 6000, (void*)path, 3, nullptr, 1);
if (ret != pdPASS) if (ret != pdPASS)
AddLog(LOG_LEVEL_INFO, PSTR("UFS: Download task failed with %d"), ret); AddLog(LOG_LEVEL_INFO, PSTR("UFS: Download task failed with %d"), ret);
yield(); yield();
@ -939,14 +939,12 @@ uint8_t UfsDownloadFile(char *file) {
#ifndef DOWNLOAD_SIZE #ifndef DOWNLOAD_SIZE
#define DOWNLOAD_SIZE 4096 #define DOWNLOAD_SIZE 4096
#endif // DOWNLOAD_SIZE #endif // DOWNLOAD_SIZE
void donload_task(void *path) { void download_task(void *path) {
File download_file; File download_file;
WiFiClient download_Client; WiFiClient download_Client;
char *file = (char*) path; char *file = (char*) path;
download_file = dfsp->open(file, UFS_FILE_READ); download_file = dfsp->open(file, UFS_FILE_READ);
free(file);
uint32_t flen = download_file.size(); uint32_t flen = download_file.size();
download_Client = Webserver->client(); download_Client = Webserver->client();
@ -960,6 +958,8 @@ void donload_task(void *path) {
break; break;
} }
} }
//snprintf_P(attachment, sizeof(attachment), PSTR("download file '%s' as '%s'"), file, cp);
//Webserver->sendHeader(F("X-Tasmota-Debug"), attachment);
snprintf_P(attachment, sizeof(attachment), PSTR("attachment; filename=%s"), cp); snprintf_P(attachment, sizeof(attachment), PSTR("attachment; filename=%s"), cp);
Webserver->sendHeader(F("Content-Disposition"), attachment); Webserver->sendHeader(F("Content-Disposition"), attachment);
WSSend(200, CT_APP_STREAM, ""); WSSend(200, CT_APP_STREAM, "");
@ -978,6 +978,7 @@ void donload_task(void *path) {
download_Client.stop(); download_Client.stop();
UfsData.download_busy = false; UfsData.download_busy = false;
vTaskDelete( NULL ); vTaskDelete( NULL );
free(path);
} }
#endif // ESP32_DOWNLOAD_TASK #endif // ESP32_DOWNLOAD_TASK