Hi,
the following report has been posted to the Cygwin list. A test application
using printf("%f") in short-lived threads uses up all memory. The test
application is very simple:
void *testThread(void *data)
{
printf("\r\n%f",1.232231212);
return(NULL);
}
int main (int argc, char *argv[])
{
pthread_t t;
while(1)
{
pthread_create(&t,NULL,testThread,NULL);
pthread_join(t,NULL);
}
return 1;
}
The cause is apparently a memory leak in ldtoa resp. dtoa. The first
time the function is called, _REENT_MP_RESULT(ptr) gets newly allocated
memory by a call to Balloc. This memory is Bfree'd in subsequent calls
to ldtoa/dtoa, but immediately re-Ballocated. Since a Ballocated area
is only actually freed in _reclaim_reent when a matching Bfree has been
called, the _REENT_MP_RESULT(ptr) memory is never actually freed and
every new thread using ldtoa/dtoa will leak this memory area when the
thread exits.
The solution is to explicitely free the _REENT_MP_RESULT(ptr) area in
_reclaim_reent. That's what the below patch does. Ok to apply?