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] Memory leak - Bootstrap CoAP temporary payload not deallocated #701

Open
parmi93 opened this issue May 26, 2023 · 0 comments
Open

Comments

@parmi93
Copy link
Contributor

parmi93 commented May 26, 2023

I noticed a big memory leak caused by the CoAP data that Wakaama receives during the bootstrap phase which are not deallocated.

Specifically, on line 203 a struct lwm2m_block_data_t and the string blockData->identifier.uri are allocated and the lwm2m_block_data_t is added to the pBlockDataHead list, which (AFAIK) holds all the temporary CoAP payloads that the bootstrap server is sending to the client (Wakaama), but this can be considered a minor issue because we are talking about a few bytes (about 24 bytes on a 32bit platform).
The biggest memory leak is caused by the buffer allocated on line 213 which contains the actual CoAP payload sent by the bootstrap server, in my case it reached a size of almost 2KB (contains x509 certificates).
https://github.com/eclipse/wakaama/blob/94506859ad202b85c4d38e3d6f946f4e884540e3/coap/block.c#L201-L216

I expected this block of data to be deleted by calling prv_deleteBootstrapServer(...)
https://github.com/eclipse/wakaama/blob/94506859ad202b85c4d38e3d6f946f4e884540e3/core/liblwm2m.c#L125-L134

So I modified this function as follows:
https://github.com/parmi93/wakaama/blob/ceddf224ea787c897ac3cb5bd4ed9defc2bd4c93/core/liblwm2m.c#L125-L147

static void prv_deleteBootstrapServer(lwm2m_server_t * serverP, void *userData)
{
    LOG("Entering");
    // TODO should we parse transaction and observation to remove the ones related to this server ?
    if (serverP->sessionH != NULL)
    {
        lwm2m_close_connection(serverP->sessionH, userData);
    }
    if (NULL != serverP->location)
    {
        lwm2m_free(serverP->location);
    }

    while(serverP->blockData != NULL)
    {
        lwm2m_block_data_t * targetP;
        targetP = serverP->blockData;
        serverP->blockData = serverP->blockData->next;
        free_block_data(targetP);
    }

    lwm2m_free(serverP);
}

Basically I copied the prv_deleteServer(...) function.

Breafly

We can use the following example code, to state that the lwm2mH->bootstrapServerList->blockData list is not freed by calling lwm2m_close(...) > prv_deleteBootstrapServerList(...) > prv_deleteBootstrapServer(...)
https://github.com/eclipse/wakaama/blob/94506859ad202b85c4d38e3d6f946f4e884540e3/examples/client/lwm2mclient.c#L864-L870
https://github.com/eclipse/wakaama/blob/94506859ad202b85c4d38e3d6f946f4e884540e3/examples/client/lwm2mclient.c#L1436-L1446

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

1 participant