This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2340R5: gattMsg memory leak when receiving notifications

Part Number: CC2340R5


Tool/software:

Hello,

I have a CC2340R5 project configured as a central, connected to another CC2340R5 as peripheral. The peripheral essentially implements the Data Stream example, but it is periodically sending data from the ADC by posting GATT notifications. Data sent is 8 bytes with a frequency of 1s. I have the code working where I can read off the values of the ADC from the central, but over time, the device stops receiving notifications.

Now, on the central device I'm noticing that every time I receive a notification from the peripheral, the available heap is decrementing which indicates that the stack is not freeing these GATT notifications. My understanding was that if these messages are created and allocated by the stack, we should not be freeing in the GATT Event handler, but clearly ROV indicates that there's a memory leak here. 

How are you supposed to handle notification messages, or are you supposed to be freeing these messages in the user application?

Here is the snippet of my ATT_HANDLE_VALUE_NOTI case from app_data.c:

case   ATT_HANDLE_VALUE_NOTI:
        {
            uint32_t remoteVal1, remoteVal2;

            attHandleValueNoti_t *rsp = (attHandleValueNoti_t*) &gattMsg->msg.handleValueInd;

            if(rsp->len == 8) {
                GPIO_toggle( CONFIG_GPIO_LED_GREEN );
                remoteVal1 = BUILD_UINT32( rsp->pValue[0], rsp->pValue[1],
                                           rsp->pValue[2], rsp->pValue[3]);
                remoteVal2 = BUILD_UINT32( rsp->pValue[4], rsp->pValue[5],
                                           rsp->pValue[6], rsp->pValue[7]);
                MenuModule_printf(APP_MENU_PROFILE_STATUS_LINE1, 0, "Notification received =  val1 = %d, val2 = %d",
                                                          remoteVal1, remoteVal2);
            }

            break;
        }

Here's a short video of the app running with the heap view showing the steadily decreasing amount of free heap:

Munan