mirror of
https://github.com/espressif/esp-idf
synced 2025-03-09 09:09:10 -04:00
Merge branch 'fix/resource_leak_in_httpd_txrx' into 'master'
fix(http_txrx): Resource leak in http_txrx Closes IDF-12529 See merge request espressif/esp-idf!37223
This commit is contained in:
commit
bf51415d86
@ -257,13 +257,13 @@ esp_err_t httpd_resp_send(httpd_req_t *r, const char *buf, ssize_t buf_len)
|
||||
ESP_LOGE(TAG, "Unable to allocate httpd send buffer");
|
||||
return ESP_ERR_HTTPD_ALLOC_MEM;
|
||||
}
|
||||
ESP_LOGD(TAG, "httpd send buffer size = %d", strlen(res_buf));
|
||||
|
||||
esp_err_t ret = snprintf(res_buf, required_size, httpd_hdr_str, ra->status, ra->content_type, buf_len);
|
||||
if (ret < 0 || ret >= required_size) {
|
||||
free(res_buf);
|
||||
return ESP_ERR_HTTPD_RESP_HDR;
|
||||
}
|
||||
ESP_LOGD(TAG, "httpd send buffer size = %d", strlen(res_buf));
|
||||
ret = httpd_send_all(r, res_buf, strlen(res_buf));
|
||||
free(res_buf);
|
||||
if (ret != ESP_OK) {
|
||||
@ -332,23 +332,23 @@ esp_err_t httpd_resp_send_chunk(httpd_req_t *r, const char *buf, ssize_t buf_len
|
||||
/* Request headers are no longer available */
|
||||
ra->req_hdrs_count = 0;
|
||||
|
||||
/* Calculate the size of the headers. +1 for the null terminator */
|
||||
size_t required_size = snprintf(NULL, 0, httpd_chunked_hdr_str, ra->status, ra->content_type) + 1;
|
||||
if (required_size > ra->max_req_hdr_len) {
|
||||
return ESP_ERR_HTTPD_RESP_HDR;
|
||||
}
|
||||
char *res_buf = malloc(required_size); /* Temporary buffer to store the headers */
|
||||
if (res_buf == NULL) {
|
||||
ESP_LOGE(TAG, "Unable to allocate httpd send chunk buffer");
|
||||
return ESP_ERR_HTTPD_ALLOC_MEM;
|
||||
}
|
||||
ESP_LOGD(TAG, "httpd send chunk buffer size = %d", strlen(res_buf));
|
||||
if (!ra->first_chunk_sent) {
|
||||
/* Calculate the size of the headers. +1 for the null terminator */
|
||||
size_t required_size = snprintf(NULL, 0, httpd_chunked_hdr_str, ra->status, ra->content_type) + 1;
|
||||
if (required_size > ra->max_req_hdr_len) {
|
||||
return ESP_ERR_HTTPD_RESP_HDR;
|
||||
}
|
||||
char *res_buf = malloc(required_size); /* Temporary buffer to store the headers */
|
||||
if (res_buf == NULL) {
|
||||
ESP_LOGE(TAG, "Unable to allocate httpd send chunk buffer");
|
||||
return ESP_ERR_HTTPD_ALLOC_MEM;
|
||||
}
|
||||
esp_err_t ret = snprintf(res_buf, required_size, httpd_chunked_hdr_str, ra->status, ra->content_type);
|
||||
if (ret < 0 || ret >= required_size) {
|
||||
free(res_buf);
|
||||
return ESP_ERR_HTTPD_RESP_HDR;
|
||||
}
|
||||
ESP_LOGD(TAG, "httpd send chunk buffer size = %d", strlen(res_buf));
|
||||
/* Size of essential headers is limited by scratch buffer size */
|
||||
ret = httpd_send_all(r, res_buf, strlen(res_buf));
|
||||
free(res_buf);
|
||||
|
Loading…
x
Reference in New Issue
Block a user