Merge branch 'backport/v1.4.2/cluster-destroy-unlink' into 'release/v1.4.2'

[v1.4.2] components/esp-matter: unlink cluster from endpoint on cluster::destroy

See merge request app-frameworks/esp-matter!1472
This commit is contained in:
Shu Chen
2026-03-25 03:10:11 +00:00
2 changed files with 9 additions and 4 deletions
@@ -1409,8 +1409,13 @@ esp_err_t destroy(cluster_t *cluster)
current_cluster->matter_attributes = NULL;
}
/* Free */
esp_matter_mem_free(current_cluster);
/* Remove from parent endpoint's cluster list and free */
_endpoint_t *parent_endpoint = (_endpoint_t *)endpoint::get(current_cluster->endpoint_id);
if (parent_endpoint) {
SinglyLinkedList<_cluster_t>::remove(&parent_endpoint->cluster_list, current_cluster);
} else {
esp_matter_mem_free(current_cluster);
}
return ESP_OK;
}
@@ -447,8 +447,8 @@ cluster_t *create(endpoint_t *endpoint, uint32_t cluster_id, uint8_t flags);
/** Destroy cluster
*
* This will destroy the cluster which has been created and added to the endpoint. It also destroys the associated
* attributes, commands and events.
* This will remove the cluster from the parent endpoint's cluster list, then destroy the cluster
* and free its associated attributes, commands and events.
*
* @param[in] cluster Cluster handle.
*