From 63c2834d7bcb44706ec1ba1cb83d170465350b84 Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Mon, 9 Sep 2019 15:02:38 +0200 Subject: [PATCH] VFS: Fix memory access after free() in UART select() Closes https://github.com/espressif/esp-idf/issues/4030 --- components/vfs/vfs_uart.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/vfs/vfs_uart.c b/components/vfs/vfs_uart.c index 7a1d11352..c413cbfb0 100644 --- a/components/vfs/vfs_uart.c +++ b/components/vfs/vfs_uart.c @@ -474,10 +474,6 @@ static esp_err_t uart_end_select(void *end_select_args) { uart_select_args_t *args = end_select_args; - if (args) { - free(args); - } - portENTER_CRITICAL(uart_get_selectlock()); esp_err_t ret = unregister_select(args); for (int i = 0; i < UART_NUM; ++i) { @@ -485,6 +481,10 @@ static esp_err_t uart_end_select(void *end_select_args) } portEXIT_CRITICAL(uart_get_selectlock()); + if (args) { + free(args); + } + return ret; }