Prevent memory leak in UART driver when message handling is slow
This commit is contained in:
parent
5c59c57a16
commit
6db8c43480
|
@ -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 ){
|
||||||
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()");
|
||||||
|
|
Loading…
Reference in New Issue