Opened on 06/14/07 at 05:29:36
Last modified on 04/01/14 at 11:25:14
#1246 closed defect (fixed)
memory leak: newlib reent struct not cleaned up from libc_delete_hook
Reported by: | strauman | Owned by: | Chris Johns |
---|---|---|---|
Priority: | normal | Milestone: | 4.11 |
Component: | fs | Version: | 4.11 |
Severity: | normal | Keywords: | |
Cc: | chrisj@…, sebastian.huber@… | Blocked By: | |
Blocking: |
Description
This issue was already discussed here
http://www.rtems.com/ml/rtems-users/2004/october/msg00282.html
and here:
http://www.rtems.com/ml/rtems-users/2004/december/msg00004.html
It would be better to use newlibc's reclaim_reent() routine to cleanup the
reent struct rather than replicating bits of that routine in the libc_delete_hook(). HOWEVER: newlibc (1.15) stdin/stdout/stderr FILE structs are
per-thread, not per-process and reclaim_reent() walks fclose() (calling fflush()) on those three FILEs. These can be illegal operations since the device
driver may block in fflush() etc. but the delete_hook is executing from a dispatch disabled section (and possibly even a different thread context).
A better hack (because it still requires tampering with the reent struct)
than what's currently used would IMO be:
from libc_delete_hook()
set _REENT->stdin->_close = 0;
_REENT->stdin->_seek = 0;
_REENT->stdin->_flags&= ~SWR;
(same for stdout, stderr) so that the fclose/fflush operation caused
by reclaim_reent() doesn't cause any device I/O.
eventually, call reclaim_reent().
Other possibilities (involving newlib patching)
- let newlib implement fpurge() and call prior to reclaim_reent() -- still requires avoiding device close operation.
- create 'rtems_stdio_cleanup' function that does exactly what fclose does but omits the fflush() and device close operations. Then attach that 'rtems_stdio_cleanup' to _REENT->cleanup
- let stdin/stdout/stderr file structs be per-process rather than per-thread objects (like all other FILEs) but this would probably require implementing locking
Attachments (2)
Change History (5)
Changed on 08/24/07 at 00:05:08 by strauman
Attachment: | PR#1246-rtems-newlibc-reclaim_reent.diff added |
---|
Changed on 08/24/07 at 00:21:02 by strauman
Attachment: | PR#1246-newlib-1.15.0-rtems_stdio_cleanup.diff added |
---|
fix newlibc's reclaim_reent() [rtems only] so it can be used to plug memory leak
comment:1 Changed on 06/04/10 at 20:51:29 by Chris Johns
Component: | cpukit → filesystem |
---|---|
Milestone: | 4.8 → 4.11 |
Owner: | changed from Joel Sherrill to Chris Johns |
Status: | new → assigned, chrisj@rtems.org |
Version: | 4.7 → HEAD |
comment:2 Changed on 04/01/14 at 11:25:14 by Sebastian Huber
Resolution: | → fixed |
---|---|
Status: | assigned → closed, sebastian.huber@embedded-brains.de |
Fixed with Newlib 2.1.0, see also libtests/newlib01.
comment:3 Changed on 11/24/14 at 18:58:28 by Gedare Bloom
Version: | HEAD → 4.11 |
---|
Replace Version=HEAD with Version=4.11 for the tickets with Milestone >= 4.11
Fix memory leak; use newlibc reclaim_reent.