Commit 6db8c434 authored by Bernd Meyer's avatar Bernd Meyer Committed by Johny Mattsson
Browse files

Prevent memory leak in UART driver when message handling is slow

parent 5c59c57a
...@@ -116,12 +116,6 @@ static void task_uart( void *pvParameters ){ ...@@ -116,12 +116,6 @@ static void task_uart( void *pvParameters ){
if(xQueueReceive(uart_status[id].queue, (void * )&event, (portTickType)portMAX_DELAY)) { if(xQueueReceive(uart_status[id].queue, (void * )&event, (portTickType)portMAX_DELAY)) {
switch(event.type) { switch(event.type) {
case UART_DATA: { case UART_DATA: {
post = (uart_event_post_t*)malloc(sizeof(uart_event_post_t));
if(post == NULL) {
ESP_LOGE(UART_TAG, "Can not alloc memory in task_uart()");
// reboot here?
continue;
}
// Attempt to coalesce received bytes to reduce risk of overrunning // Attempt to coalesce received bytes to reduce risk of overrunning
// the task event queue. // the task event queue.
size_t len; size_t len;
...@@ -129,6 +123,13 @@ static void task_uart( void *pvParameters ){ ...@@ -129,6 +123,13 @@ static void task_uart( void *pvParameters ){
len = event.size; len = event.size;
if (len == 0) if (len == 0)
continue; // we already gobbled all the bytes continue; // we already gobbled all the bytes
post = (uart_event_post_t*)malloc(sizeof(uart_event_post_t));
if(post == NULL) {
ESP_LOGE(UART_TAG, "Can not alloc memory in task_uart()");
// reboot here?
continue;
}
post->data = malloc(len); post->data = malloc(len);
if(post->data == NULL) { if(post->data == NULL) {
ESP_LOGE(UART_TAG, "Can not alloc memory in task_uart()"); ESP_LOGE(UART_TAG, "Can not alloc memory in task_uart()");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment