joelguittet / mender-mcu-client

Mender client for MCU, just because it's cool to have it
MIT License
31 stars 4 forks source link

Memory leak in mender-artifact after downloading a new deployment #39

Closed joelguittet closed 3 weeks ago

joelguittet commented 2 months ago

While downloading a new deployment, a memory leak is observed in mender-artifact. See attached valgrind report. First analysis shows that the ctx->file.name is not always freed during the parsing process.

==156569== Thread 1:
==156569== 25 bytes in 2 blocks are definitely lost in loss record 1 of 3
==156569==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==156569==    by 0x49CD38E: strdup (strdup.c:42)
==156569==    by 0x196191: mender_artifact_process_data (in /home/ubuntu/mender-mcu-client/github/mender-mcu-client/tests/build/mender-mcu-client.elf)
==156569==    by 0x1945AF: mender_api_http_artifact_callback (in /home/ubuntu/mender-mcu-client/github/mender-mcu-client/tests/build/mender-mcu-client.elf)
==156569==    by 0x1966D5: mender_http_write_callback (in /home/ubuntu/mender-mcu-client/github/mender-mcu-client/tests/build/mender-mcu-client.elf)
==156569==    by 0x48D6C04: Curl_client_write (in /usr/local/lib/libcurl.so.4.8.0)
==156569==    by 0x48E8D0F: Curl_readwrite (in /usr/local/lib/libcurl.so.4.8.0)
==156569==    by 0x48CE89B: multi_runsingle (in /usr/local/lib/libcurl.so.4.8.0)
==156569==    by 0x48CFE79: curl_multi_perform (in /usr/local/lib/libcurl.so.4.8.0)
==156569==    by 0x48ABF1A: curl_easy_perform (in /usr/local/lib/libcurl.so.4.8.0)
==156569==    by 0x1969FC: mender_http_perform (in /home/ubuntu/mender-mcu-client/github/mender-mcu-client/tests/build/mender-mcu-client.elf)
==156569==    by 0x1951B1: mender_api_download_artifact (in /home/ubuntu/mender-mcu-client/github/mender-mcu-client/tests/build/mender-mcu-client.elf)
==156569== 
==156569== 57 bytes in 2 blocks are definitely lost in loss record 2 of 3
==156569==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==156569==    by 0x195FB6: mender_artifact_process_data (in /home/ubuntu/mender-mcu-client/github/mender-mcu-client/tests/build/mender-mcu-client.elf)
==156569==    by 0x1945AF: mender_api_http_artifact_callback (in /home/ubuntu/mender-mcu-client/github/mender-mcu-client/tests/build/mender-mcu-client.elf)
==156569==    by 0x1966D5: mender_http_write_callback (in /home/ubuntu/mender-mcu-client/github/mender-mcu-client/tests/build/mender-mcu-client.elf)
==156569==    by 0x48D6C04: Curl_client_write (in /usr/local/lib/libcurl.so.4.8.0)
==156569==    by 0x48E8D0F: Curl_readwrite (in /usr/local/lib/libcurl.so.4.8.0)
==156569==    by 0x48CE89B: multi_runsingle (in /usr/local/lib/libcurl.so.4.8.0)
==156569==    by 0x48CFE79: curl_multi_perform (in /usr/local/lib/libcurl.so.4.8.0)
==156569==    by 0x48ABF1A: curl_easy_perform (in /usr/local/lib/libcurl.so.4.8.0)
==156569==    by 0x1969FC: mender_http_perform (in /home/ubuntu/mender-mcu-client/github/mender-mcu-client/tests/build/mender-mcu-client.elf)
==156569==    by 0x1951B1: mender_api_download_artifact (in /home/ubuntu/mender-mcu-client/github/mender-mcu-client/tests/build/mender-mcu-client.elf)
==156569==    by 0x18F671: mender_client_work_function (in /home/ubuntu/mender-mcu-client/github/mender-mcu-client/tests/build/mender-mcu-client.elf)
joelguittet commented 3 weeks ago

Memory leak identified in mender_artifact_parse_tar_header, will be fixed asap.