Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG:A problem about registration update that can cause a memory leak. #811

Open
xiaoshan1234 opened this issue Sep 25, 2024 · 1 comment

Comments

@xiaoshan1234
Copy link

Detail

When the client registration update message receives no reply, the callback function cannot fully release the allocated memory。
I made some modifications to fix this issue, and it truly worked in my business. I hope more people can test my changes to see if they introduce any new problems

Original Code

static void prv_handleRegistrationUpdateReply(lwm2m_context_t * contextP,
                                              lwm2m_transaction_t * transacP,
                                              void * message)
{
    coap_packet_t * packet = (coap_packet_t *)message;
    registration_data_t * dataP = (registration_data_t *)(transacP->userData);

   // ......
    
    if (packet != NULL && packet->code != COAP_231_CONTINUE)
    {
        lwm2m_free(dataP->payload);
        transaction_free_userData(contextP, transacP);
    }
}

My Code

static void prv_handleRegistrationUpdateReply(lwm2m_context_t * contextP,
                                              lwm2m_transaction_t * transacP,
                                              void * message)
{
    coap_packet_t * packet = (coap_packet_t *)message;
    registration_data_t * dataP = (registration_data_t *)(transacP->userData);

   // ......
    
    if (packet != NULL && packet->code == COAP_231_CONTINUE)
    {
        ; // pass 
    }
    else
    {
        uint8_t * payload = dataP->payload;
        if (transaction_free_userData(contextP, transacP))
        {
            lwm2m_free(payload);
        }
    }

}
@xiaoshan1234 xiaoshan1234 changed the title BUG:A problem about registion update that can cause a memory leak. BUG:A problem about registration update that can cause a memory leak. Sep 25, 2024
@LukasWoodtli
Copy link
Contributor

Thank you for your contribution. Would you consider making a proper PR with your changes? That would be awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants