|
@@ -1004,26 +1004,28 @@ void register_server_file_uri(httpd_handle_t server, const char *base_path)
|
|
|
{
|
|
{
|
|
|
static struct file_server_data *server_data = NULL;
|
|
static struct file_server_data *server_data = NULL;
|
|
|
|
|
|
|
|
- /* Validate file storage base path */
|
|
|
|
|
- if (!base_path)
|
|
|
|
|
|
|
+ if (server == NULL)
|
|
|
{
|
|
{
|
|
|
- // if (!base_path || strcmp(base_path, "/spiffs") != 0) {
|
|
|
|
|
- LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "File server base_path not set");
|
|
|
|
|
- // return ESP_ERR_INVALID_ARG;
|
|
|
|
|
|
|
+ LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "File server handle is not available");
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (server_data)
|
|
|
|
|
|
|
+ /* Validate file storage base path */
|
|
|
|
|
+ if (base_path == NULL || base_path[0] == '\0')
|
|
|
{
|
|
{
|
|
|
- LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "File server already started");
|
|
|
|
|
- // return ESP_ERR_INVALID_STATE;
|
|
|
|
|
|
|
+ LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "File server base_path not set");
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /* Allocate memory for server data */
|
|
|
|
|
- server_data = (file_server_data *)calloc(1, sizeof(struct file_server_data));
|
|
|
|
|
- if (!server_data)
|
|
|
|
|
|
|
+ /* Reuse the same context on server restarts instead of overwriting and leaking it. */
|
|
|
|
|
+ if (server_data == NULL)
|
|
|
{
|
|
{
|
|
|
- LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to allocate memory for server data");
|
|
|
|
|
- // return ESP_ERR_NO_MEM;
|
|
|
|
|
|
|
+ server_data = (file_server_data *)calloc(1, sizeof(struct file_server_data));
|
|
|
|
|
+ if (server_data == NULL)
|
|
|
|
|
+ {
|
|
|
|
|
+ LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Failed to allocate memory for server data");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
strlcpy(server_data->base_path, base_path,
|
|
strlcpy(server_data->base_path, base_path,
|
|
|
sizeof(server_data->base_path));
|
|
sizeof(server_data->base_path));
|