Prevent memory leak in UART driver when message handling is slow

This commit is contained in:
Bernd Meyer 2021-11-04 18:55:08 +11:00 committed by Johny Mattsson
parent 5c59c57a16
commit 6db8c43480
1 changed files with 7 additions and 6 deletions

View File

@ -116,12 +116,6 @@ static void task_uart( void *pvParameters ){
if(xQueueReceive(uart_status[id].queue, (void * )&event, (portTickType)portMAX_DELAY)) {
switch(event.type) {
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
// the task event queue.
size_t len;
@ -129,6 +123,13 @@ static void task_uart( void *pvParameters ){
len = event.size;
if (len == 0)
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);
if(post->data == NULL) {
ESP_LOGE(UART_TAG, "Can not alloc memory in task_uart()");