toniebox-reverse-engineering / teddycloud

teddyCloud is an open source server replacement for the Boxine Cloud
https://toniebox-reverse-engineering.github.io/docs/tools/teddycloud/
GNU General Public License v2.0
483 stars 36 forks source link

Fix memory leaks #259

Closed rigomate closed 5 days ago

rigomate commented 1 week ago

Reopened pull request #256 The pull request is now targeting develop, it has been rebased on develop.

There were 5 memory leaks, which were caught by the tool: infer and clang-tidy

  1. src/handler_api.c was an exit path before the free and a forgotten free
  2. src/json_helper.c Is now a rather ugly construct, but is necessary so the variable named string can be freed.
  3. src/main.c a forgotten free
  4. src/tonie_audio_playlist.c an exit path without freeing allocs

It must be mentioned though, that some more tweaking should be done, as osAllocMem could actually fail (unlikely, but not unheard). Return values of allocations are nowhere really handled, so this PR just addresses the obvious memory leaking.

SciLor commented 5 days ago

Thank you for digging in that deep and fixing the memory leaks, the details + naming the used tools.

We may drive a general approach for the allocations to exit teddyCloud when OOM. Currently teddyCloud would just crash, at least in the sanitized versions on debian/ubuntu.

rigomate commented 1 day ago

Sure thing. You also keep up the good work! I just checked and I am impressed by your github workflows. You have got sanitizer tests running. Nice! Maybe I can chip in, and set up the tools I have used, to be part of your CI. (clang-tidy, infer, cppcheck) Obviously there is some noise to them, but if the info is there then it can be investigated.

Let me see if I find the time. Cheers!

SciLor commented 1 day ago

It would be great, if you could integrate it. I think it would be nice, if this would be an additional step in the makefile, which could be run as additional step in the builds and of cause during development if needed.

If you are low on time, it would be already enough to give some details about your workflow, so I may replicate it myself.