Daniel kalu
Daniel kalu
DIIDevHeads IoT Integration Server
Created by Daniel kalu on 8/12/2024 in #edge-networking
How to Detect and Fix Memory Leaks in ESP32 FreeRTOS Home Automation Project?
Hi guys I'm working on an ESP32 home automation project using FreeRTOS and MQTT, but the system crashes after a few hours with the error message "Heap allocation failed". I suspect a memory leak in my createTask function:
void createTask(void *pvParameter) {
uint8_t *buffer = malloc(1024);
// Task processing logic
vTaskDelete(NULL);
}
void createTask(void *pvParameter) {
uint8_t *buffer = malloc(1024);
// Task processing logic
vTaskDelete(NULL);
}
The crash is characterized by a gradual decrease in available memory, leading to a "Guru Meditation Error: Core 0 panic'ed (Heap Allocation Failed)". To troubleshoot, I monitored heap usage with heap_caps_get_free_size(MALLOC_CAP_8BIT) and heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT), observed a decrease in free memory, verified task creation and deletion with uxTaskGetNumberOfTasks(), and reviewed other code sections for leaks but found none. I need help with detecting and fixing memory leaks in ESP32 with FreeRTOS and also suggestions for improving memory management and stability.
5 replies