fix(async_handler): Async handler example scratch buffer fix

1. In httpd_req_async_handler_begin, the httpd_req_aux is locally malloced
and data is  done memcpy to local httpd_req_aux from request'ss httpd_req_aux for
async request use-case, this causes scartch pointer from these two structs
pointing to same memory address.
2. In current workflow, the request's sratch buffer is freed in httpd_parse.c
httpd_req_cleanup api. Therefore if the user try to fetch the data (like headers)
from the scratch buffer, data will be not available.
3. Each request should have the deep copy of the scratch buffer. To retrive
the data later.

Closes https://github.com/espressif/esp-idf/issues/15587
This commit is contained in:
hrushikesh.bhosale
2025-04-17 11:50:21 +05:30
committed by Mahavir Jain
parent fc5bf27160
commit b6d4fa2c2e
2 changed files with 48 additions and 1 deletions

View File

@@ -647,6 +647,18 @@ esp_err_t httpd_req_async_handler_begin(httpd_req_t *r, httpd_req_t **out)
struct httpd_req_aux *async_aux = (struct httpd_req_aux *) async->aux;
struct httpd_req_aux *r_aux = (struct httpd_req_aux *) r->aux;
if (r_aux->scratch) {
async_aux->scratch = malloc(r_aux->scratch_cur_size);
if (async_aux->scratch == NULL) {
free(async_aux);
free(async);
return ESP_ERR_NO_MEM;
}
memcpy(async_aux->scratch, r_aux->scratch, r_aux->scratch_cur_size);
} else {
async_aux->scratch = NULL;
}
async_aux->resp_hdrs = calloc(hd->config.max_resp_headers, sizeof(struct resp_hdr));
if (async_aux->resp_hdrs == NULL) {
free(async_aux);