mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
fix(protocomm): roll back transport endpoint on alloc failure
In protocomm_add_endpoint_internal(), the transport-specific endpoint is registered via pc->add_endpoint() before the protocomm_ep_t bookkeeping node is allocated. If that calloc() fails, the function returned ESP_ERR_NO_MEM without unregistering the transport endpoint, leaking a URI/handler registration that has no matching protocomm endpoint and can never be removed via protocomm_remove_endpoint(). Unregister the transport endpoint on the allocation-failure path. Closes SEC-582
This commit is contained in:
@@ -99,6 +99,9 @@ static esp_err_t protocomm_add_endpoint_internal(protocomm_t *pc, const char *ep
|
|||||||
ep = (protocomm_ep_t *) calloc(1, sizeof(protocomm_ep_t));
|
ep = (protocomm_ep_t *) calloc(1, sizeof(protocomm_ep_t));
|
||||||
if (!ep) {
|
if (!ep) {
|
||||||
ESP_LOGE(TAG, "Error allocating endpoint resource");
|
ESP_LOGE(TAG, "Error allocating endpoint resource");
|
||||||
|
if (pc->remove_endpoint) {
|
||||||
|
pc->remove_endpoint(ep_name);
|
||||||
|
}
|
||||||
return ESP_ERR_NO_MEM;
|
return ESP_ERR_NO_MEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user