n1vg wrote on Saturday, November 03, 2018:
I’ve got a problem that has me going in too many directions at once and I’m hoping someone here might be able to give me some direction.
All of my tasks save one are started once and are never terminated. The one exception is a network update downloader that of course only needs to run occasionally. It’s started, checks for updates, and ends - and it takes a chunk of heap with it, even if no explicit dynamic allocation is used in the task itself.
The leak is 1468 bytes, or 436 if stdout buffering is disabled. Assuming 8 bytes of overhead per allocation, that matches perfectly with the size of the reent structure and the default 1024 byte stdout buffer.
Presumably Newlib expects the OS to clean up after it. Or is there some way to tell it to free what it’s using?
I’m using Newlib’s own malloc for the kernel (configUSE_HEAP_SCHEME==6) - this comes from Dave Nadler by way of mcuoneclipse.com.
How does one normally deal with this? This can’t be an unusual requirement, to shut down a task without leaking memory. I’m trying to recall the reasons I switched heap schemes in the first place - I think initially I was using the CodeWarrior EWL library, which had a heap implementation that didn’t match the documentation, didn’t behave as expected, and has apparently been abandoned.
What I want is a setup that will let me use standard libraries in a thread-safe manner and either not have a separate heap for the RTOS and standard libaries, or at least have a heap that goes where the documentation says it will and plays nice with everything else. (This is all on a Cortex M4, BTW.)
What am I missing? This seems like it should be a really basic thing and I must be overlooking something obvious, but it’s Friday night and I’m already sleep-deprived and 80 hours into my work week and I’d just like to hear how everyone else deals with this.
Thanks,
Scott