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

memory leak in prv_getParameters() reported by valgrind #383

Closed
Kevin0626 opened this issue Jul 14, 2018 · 3 comments
Closed

memory leak in prv_getParameters() reported by valgrind #383

Kevin0626 opened this issue Jul 14, 2018 · 3 comments
Labels

Comments

@Kevin0626
Copy link
Contributor

Hi, The Valgrind reported one definitely loss in the prv_getParameters() for version information allocation.

This function has big burden to free the memory for each exit port. We would suggest to use a label in the function and all exit must go to the label. That will easy manage the memory free situations.

==22838== 8 bytes in 2 blocks are definitely lost in loss record 12 of 246
==22838== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==22838== by 0xE3D5EB5: lwm2m_malloc (platform.c:28)
==22838== by 0xE3CAB8E: prv_getParameters (registration.c:670)
==22838== by 0xE3CB990: registration_handleRequest (registration.c:1061)
==22838== by 0xE3C935F: handle_request (packet.c:172)
==22838== by 0xE3C9634: lwm2m_handle_packet (packet.c:299)
==22838== by 0xE3C0765: thread_lwm2m (lwm2mserver.c:237)
==22838== by 0x506A9FD: ThreadWrapper (in /media/beihai/WangXin-Fun/ssg-sto-crtl-iot-idrm/plugin-sdk/azure_base/host/lib/azure_iot_gateway_sdk-1.0.6/libgateway.so)
==22838== by 0x584D6B9: start_thread (pthread_create.c:333)

    else if (lwm2m_strncmp((char *)query->data, QUERY_VERSION, QUERY_VERSION_LEN) == 0)
    {
        if (*versionP != NULL) goto error;
        if (query->len == QUERY_VERSION_LEN) goto error;

line 670 --->        *versionP = (char *)lwm2m_malloc(query->len - QUERY_VERSION_LEN + 1);
        if (*versionP != NULL)
        {
            memcpy(*versionP, query->data + QUERY_VERSION_LEN, query->len - QUERY_VERSION_LEN);
            (*versionP)[query->len - QUERY_VERSION_LEN] = 0;
        }
    }
@davidgraeff
Copy link

I have reported this as well in #368.
And my solution would actually be to move the codebase to c++ (#369). It is just too hard to get object lifetime right in C and also maintain a correct code, while accepting contributions from external people with different backgrounds and knowledge of the code.

@sbertin-telular
Copy link
Contributor

I believe this has been fixed by pull request #418

@sbernard31 sbernard31 added the bug label Nov 3, 2020
@sbernard31
Copy link
Contributor

It should be fixed. Do not hesitate to reopen if this is not.
Maybe should be backport on 1.x branch (#487)

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

No branches or pull requests

4 participants