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:
Aditya Patwardhan
2026-09-21 11:41:59 +05:30
parent 23bd88f392
commit f0d7736076
@@ -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));
if (!ep) {
ESP_LOGE(TAG, "Error allocating endpoint resource");
if (pc->remove_endpoint) {
pc->remove_endpoint(ep_name);
}
return ESP_ERR_NO_MEM;
}