diff --git a/components/esp_http_server/src/httpd_sess.c b/components/esp_http_server/src/httpd_sess.c index 0f722211a..333c1d3f3 100644 --- a/components/esp_http_server/src/httpd_sess.c +++ b/components/esp_http_server/src/httpd_sess.c @@ -78,7 +78,11 @@ esp_err_t httpd_sess_new(struct httpd_data *hd, int newfd) /* Call user-defined session opening function */ if (hd->config.open_fn) { esp_err_t ret = hd->config.open_fn(hd, hd->hd_sd[i].fd); - if (ret != ESP_OK) return ret; + if (ret != ESP_OK) { + httpd_sess_delete(hd, hd->hd_sd[i].fd); + ESP_LOGD(TAG, LOG_FMT("open_fn failed for fd = %d"), newfd); + return ret; + } } return ESP_OK; }