impure_data never reclaimed

Fabian Vogt <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
Hi,

I'm using newlib as libc on top of an OS which provides malloc and free.
Threads aren't supported, but programs can be started and stopped. The used
heap is shared between all programs, so leaked memory is lost forever. Thus
it is important that after a clean exit, every allocation was properly freed.

Currently this simple program leaks three allocations though:

#include <stdio.h>
int main()
{
    setbuf(stdout, NULL); // This would be properly freed, avoid distraction
    printf("This is 0.5 as a float: %f\n", 0.5f);
}

Those are from Balloc, which allocates a list also for later use.
FWICT, _reclaim_reent takes care of freeing the list and its contents, but:
- _reclaim_reent is never called for _impure_ptr (== &impure_data)
- _reclaim_reent does nothing if impure_ptr is passed

Is the OS glue code supposed to do something like this in _exit?

    struct _reent *global_reent = _impure_ptr;
    _impure_ptr = NULL;
    _reclaim_reent(global_reent);

With that the leaks are gone, but it seems a bit odd to me.

Thanks,
Fabian
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.