fix(console): Memory leaks after deinit

This commit is contained in:
Guillaume Souchere
2025-02-06 13:21:03 +01:00
parent 5b2f2e05f3
commit 203b3b5a4e
8 changed files with 62 additions and 6 deletions
@@ -10,7 +10,12 @@
#include <sys/time.h>
// Some resources are lazy allocated (newlib locks) in the console code, the threshold is left for that case
#define TEST_MEMORY_LEAK_THRESHOLD (150)
#define TEST_MEMORY_LEAK_THRESHOLD_DEFAULT (150)
static int leak_threshold = TEST_MEMORY_LEAK_THRESHOLD_DEFAULT;
void set_leak_threshold(int threshold)
{
leak_threshold = threshold;
}
void setUp(void)
{
@@ -19,7 +24,8 @@ void setUp(void)
void tearDown(void)
{
unity_utils_evaluate_leaks_direct(TEST_MEMORY_LEAK_THRESHOLD);
unity_utils_evaluate_leaks_direct(leak_threshold);
leak_threshold = TEST_MEMORY_LEAK_THRESHOLD_DEFAULT;
}
void app_main(void)
@@ -154,8 +154,11 @@ TEST_CASE("esp console repl test", "[console][ignore]")
vTaskDelay(pdMS_TO_TICKS(2000));
}
extern void set_leak_threshold(int threshold);
TEST_CASE("esp console repl deinit", "[console][ignore]")
{
set_leak_threshold(400);
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
TEST_ESP_OK(esp_console_new_repl_uart(&uart_config, &repl_config, &s_repl));
@@ -165,14 +168,17 @@ TEST_CASE("esp console repl deinit", "[console][ignore]")
/* wait to make sure the task reaches linenoiseEdit function
* and gets stuck in the select */
vTaskDelay(pdMS_TO_TICKS(500));
vTaskDelay(pdMS_TO_TICKS(10));
/* call the delete function, this returns only when the repl task terminated */
const esp_err_t res = s_repl->del(s_repl);
/* wait to make sure the task reaches linenoiseEdit function
* and gets stuck in the select */
vTaskDelay(pdMS_TO_TICKS(10));
/* if this point is reached, the repl environment has been deleted successfully */
TEST_ASSERT(res == ESP_OK);
printf("-------------- %p\n", s_repl);
}
static const esp_console_cmd_t cmd_a = {