From 997f9dd1838f550d3a4bdb96492868e0a364eb4a Mon Sep 17 00:00:00 2001 From: yuanjianmin Date: Fri, 26 May 2023 14:14:12 +0800 Subject: [PATCH] example: Fix memory leak in ws_echo_server when httpd_queue_work failed Closes https://github.com/espressif/esp-idf/issues/11507 --- .../http_server/ws_echo_server/main/ws_echo_server.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/protocols/http_server/ws_echo_server/main/ws_echo_server.c b/examples/protocols/http_server/ws_echo_server/main/ws_echo_server.c index c8789f73f3d6..a9823a4a30b6 100644 --- a/examples/protocols/http_server/ws_echo_server/main/ws_echo_server.c +++ b/examples/protocols/http_server/ws_echo_server/main/ws_echo_server.c @@ -55,9 +55,16 @@ static void ws_async_send(void *arg) static esp_err_t trigger_async_send(httpd_handle_t handle, httpd_req_t *req) { struct async_resp_arg *resp_arg = malloc(sizeof(struct async_resp_arg)); + if (resp_arg == NULL) { + return ESP_ERR_NO_MEM; + } resp_arg->hd = req->handle; resp_arg->fd = httpd_req_to_sockfd(req); - return httpd_queue_work(handle, ws_async_send, resp_arg); + esp_err_t ret = httpd_queue_work(handle, ws_async_send, resp_arg); + if (ret != ESP_OK) { + free(resp_arg); + } + return ret; } /*