public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* RE: Possible bug in __sfp() libc routine
@ 2017-04-07 22:02 Kapania, Ashish
  0 siblings, 0 replies; 6+ messages in thread
From: Kapania, Ashish @ 2017-04-07 22:02 UTC (permalink / raw)
  To: newlib

Slight correction in my previous email. __sfp() is in "libc/stdio/findfp.c" not "libc/findfp.c".

> -----Original Message-----
> From: Kapania, Ashish
> Sent: Friday, April 07, 2017 2:58 PM
> To: newlib@sourceware.org
> Subject: Possible bug in __sfp() libc routine
> 
> Hi All,
> 
> In the __sfp() function in "libc/findfp.c" file, I see that if no free FILE object is
> found, one is allocated and put on a list in the global re-entrancy structure
> (_GLOBAL_REENT). This seems like a bug to me. I believe the FILE object should
> be put on a list in the thread specific reentrancy structure. If I create a thread,
> do a fopen, do a fwrite (invokes __sfp which in turn allocates the FILE object),
> do a fclose and then delete the thread, the FILE object allocated by __sfp() is not
> freed. If a do this sequence repeatedly, I see memory keeps leaking until my app
> runs out of heap. I have a separate re-entrancy structure for each thread but
> because the FILE object is not in a list on the local re-entrancy structure, it does
> not get freed when I delete the thread and run _reclaim_reent() on the local
> reentrancy structure.
> 
> Any thoughts ?
> 
> Best,
> Ashish

^ permalink raw reply	[flat|nested] 6+ messages in thread
* Possible bug in __sfp() libc routine
@ 2017-04-07 21:58 Kapania, Ashish
  2017-04-08 21:04 ` Freddie Chopin
  2017-04-09  9:22 ` Martin Velek
  0 siblings, 2 replies; 6+ messages in thread
From: Kapania, Ashish @ 2017-04-07 21:58 UTC (permalink / raw)
  To: newlib

Hi All,

In the __sfp() function in "libc/findfp.c" file, I see that if no free FILE object is found, one is allocated and put on a list in the global re-entrancy structure (_GLOBAL_REENT). This seems like a bug to me. I believe the FILE object should be put on a list in the thread specific reentrancy structure. If I create a thread, do a fopen, do a fwrite (invokes __sfp which in turn allocates the FILE object), do a fclose and then delete the thread, the FILE object allocated by __sfp() is not freed. If a do this sequence repeatedly, I see memory keeps leaking until my app runs out of heap. I have a separate re-entrancy structure for each thread but because the FILE object is not in a list on the local re-entrancy structure, it does not get freed when I delete the thread and run _reclaim_reent() on the local reentrancy structure.

Any thoughts ?

Best,
Ashish

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-01-19  0:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-07 22:02 Possible bug in __sfp() libc routine Kapania, Ashish
  -- strict thread matches above, loose matches on Subject: below --
2017-04-07 21:58 Kapania, Ashish
2017-04-08 21:04 ` Freddie Chopin
2017-04-10 19:53   ` Kapania, Ashish
2017-04-09  9:22 ` Martin Velek
2018-01-19  0:31   ` Kapania, Ashish

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).