Merge branch 'contrib/github_pr_13462' into 'master'

fix: Allocate HTTP header space for async httpd_req_t objects (GitHub PR)

Closes IDFGH-12445

See merge request espressif/esp-idf!29868
This commit is contained in:
Aditya Patwardhan
2024-04-22 14:17:21 +08:00

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -614,6 +614,19 @@ esp_err_t httpd_req_async_handler_begin(httpd_req_t *r, httpd_req_t **out)
} }
memcpy(async->aux, r->aux, sizeof(struct httpd_req_aux)); memcpy(async->aux, r->aux, sizeof(struct httpd_req_aux));
// Copy response header block
struct httpd_data *hd = (struct httpd_data *) r->handle;
struct httpd_req_aux *async_aux = (struct httpd_req_aux *) async->aux;
struct httpd_req_aux *r_aux = (struct httpd_req_aux *) r->aux;
async_aux->resp_hdrs = calloc(hd->config.max_resp_headers, sizeof(struct resp_hdr));
if (async_aux->resp_hdrs == NULL) {
free(async_aux);
free(async);
return ESP_ERR_NO_MEM;
}
memcpy(async_aux->resp_hdrs, r_aux->resp_hdrs, hd->config.max_resp_headers * sizeof(struct resp_hdr));
// mark socket as "in use" // mark socket as "in use"
struct httpd_req_aux *ra = r->aux; struct httpd_req_aux *ra = r->aux;
ra->sd->for_async_req = true; ra->sd->for_async_req = true;
@@ -632,6 +645,7 @@ esp_err_t httpd_req_async_handler_complete(httpd_req_t *r)
struct httpd_req_aux *ra = r->aux; struct httpd_req_aux *ra = r->aux;
ra->sd->for_async_req = false; ra->sd->for_async_req = false;
free(ra->resp_hdrs);
free(r->aux); free(r->aux);
free(r); free(r);