Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf_memobj_put not called if log message exceeds serial buffer len in nrf_log_backend_flash.c

There appears to be a potential bug innrf_log_backend_flash function log_msg_queue_process ()....  

In the case where the log message exceeds the serialization buffer size the message is dropped but nrf_memobj_put is not called.  This will leave the current message marked as in-use forever in other words its a memory leak.

The code in question:

static void log_msg_queue_process(nrf_queue_t const * p_queue)
{
    nrf_log_entry_t * p_msg;
    bool              busy = false;
    while (nrf_queue_pop(p_queue, &p_msg) == NRF_SUCCESS)
    {
        ret_code_t err_code;

        m_curr_len = sizeof(m_flash_buf);
        if (!msg_to_buf(p_msg, (uint8_t *)m_flash_buf, &m_curr_len))
        {
            continue;
        }

needs to include nrf_memobj_put(p_msg)  AND m_dropped++

static void log_msg_queue_process(nrf_queue_t const * p_queue)
{
    nrf_log_entry_t * p_msg;
    bool              busy = false;
    while (nrf_queue_pop(p_queue, &p_msg) == NRF_SUCCESS)
    {
        ret_code_t err_code;

        m_curr_len = sizeof(m_flash_buf);
        if (!msg_to_buf(p_msg, (uint8_t *)m_flash_buf, &m_curr_len))
        {

            nrf_memobj_put(p_msg);

           m_dropped++;
            continue;
        }

Or am I missing something?

Related