diff --git a/components/esp_http_client/esp_http_client.c b/components/esp_http_client/esp_http_client.c index 194a7ad06d..b059a58db0 100644 --- a/components/esp_http_client/esp_http_client.c +++ b/components/esp_http_client/esp_http_client.c @@ -621,14 +621,22 @@ esp_err_t esp_http_client_cleanup(esp_http_client_handle_t client) } esp_http_client_close(client); esp_transport_list_destroy(client->transport_list); - http_header_destroy(client->request->headers); - free(client->request->buffer->data); - free(client->request->buffer); - free(client->request); - http_header_destroy(client->response->headers); - free(client->response->buffer->data); - free(client->response->buffer); - free(client->response); + if (client->request) { + http_header_destroy(client->request->headers); + if (client->request->buffer) { + free(client->request->buffer->data); + } + free(client->request->buffer); + free(client->request); + } + if (client->response) { + http_header_destroy(client->response->headers); + if (client->response->buffer) { + free(client->response->buffer->data); + } + free(client->response->buffer); + free(client->response); + } free(client->parser); free(client->parser_settings); @@ -700,7 +708,10 @@ esp_err_t esp_http_client_set_url(esp_http_client_handle_t client, const char *u if (purl.field_data[UF_HOST].len) { http_utils_assign_string(&client->connection_info.host, url + purl.field_data[UF_HOST].off, purl.field_data[UF_HOST].len); - HTTP_MEM_CHECK(TAG, client->connection_info.host, return ESP_ERR_NO_MEM); + HTTP_MEM_CHECK(TAG, client->connection_info.host, { + free(old_host); + return ESP_ERR_NO_MEM; + }); } // Close the connection if host was changed if (old_host && client->connection_info.host diff --git a/components/esp_local_ctrl/src/esp_local_ctrl_handler.c b/components/esp_local_ctrl/src/esp_local_ctrl_handler.c index 23a92abd6c..f5674fe2f7 100644 --- a/components/esp_local_ctrl/src/esp_local_ctrl_handler.c +++ b/components/esp_local_ctrl/src/esp_local_ctrl_handler.c @@ -214,7 +214,7 @@ static void esp_local_ctrl_command_cleanup(LocalCtrlMessage *resp, void **ctx) if (resp->resp_get_prop_vals) { prop_val_free_fn_t *free_fns = (prop_val_free_fn_t *)(*ctx); for (size_t i = 0; i < resp->resp_get_prop_vals->n_props; i++) { - if (free_fns[i]) { + if (free_fns && free_fns[i]) { free_fns[i](resp->resp_get_prop_vals->props[i]->value.data); } free(resp->resp_get_prop_vals->props[i]); diff --git a/components/esp_netif/esp_netif_objects.c b/components/esp_netif/esp_netif_objects.c index 2c23126bf9..23a2c6dde7 100644 --- a/components/esp_netif/esp_netif_objects.c +++ b/components/esp_netif/esp_netif_objects.c @@ -76,6 +76,7 @@ esp_err_t esp_netif_add_to_list(esp_netif_t *netif) item->netif = netif; if ((ret = esp_netif_list_lock()) != ESP_OK) { + free(item); return ret; } diff --git a/components/esp_timer/src/esp_timer.c b/components/esp_timer/src/esp_timer.c index 0a7d95d764..2bbb439e5e 100644 --- a/components/esp_timer/src/esp_timer.c +++ b/components/esp_timer/src/esp_timer.c @@ -281,7 +281,11 @@ static void timer_process_alarm(esp_timer_dispatch_t dispatch_method) int64_t now = esp_timer_impl_get_time(); esp_timer_handle_t it = LIST_FIRST(&s_timers); while (it != NULL && - it->alarm < now) { + it->alarm < now) { // NOLINT(clang-analyzer-unix.Malloc) + // Static analyser reports "Use of memory after it is freed" since the "it" variable + // is freed below (if EVENT_ID_DELETE_TIMER) and assigned to the (new) LIST_FIRST() + // so possibly (if the "it" hasn't been removed from the list) it might keep the same ptr. + // Ignoring this warning, as this couldn't happen if queue.h used to populate the list LIST_REMOVE(it, list_entry); if (it->event_id == EVENT_ID_DELETE_TIMER) { free(it);