From c9a4da01c6d7e6f55e6c30769c410ca5e956dcd3 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Wed, 26 Nov 2003 17:53:30 +0000 Subject: 2003-11-26 Joel Sherrill PR 524/filesystem * src/newlibc.c: Address 1K buffer leak from incomplete cleanup of newlib reentrancy handler. --- cpukit/libcsupport/ChangeLog | 6 ++++++ cpukit/libcsupport/src/newlibc.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) (limited to 'cpukit') diff --git a/cpukit/libcsupport/ChangeLog b/cpukit/libcsupport/ChangeLog index eb44f4a487..a2304b2797 100644 --- a/cpukit/libcsupport/ChangeLog +++ b/cpukit/libcsupport/ChangeLog @@ -1,3 +1,9 @@ +2003-11-26 Joel Sherrill + + PR 524/filesystem + * src/newlibc.c: Address 1K buffer leak from incomplete cleanup of + newlib reentrancy handler. + 2003-11-26 Joel Sherrill PR 523/filesystem diff --git a/cpukit/libcsupport/src/newlibc.c b/cpukit/libcsupport/src/newlibc.c index 13c600731a..dcd7dae3b2 100644 --- a/cpukit/libcsupport/src/newlibc.c +++ b/cpukit/libcsupport/src/newlibc.c @@ -42,6 +42,8 @@ #include +int _fwalk(struct _reent *ptr, int (*function) (FILE *) ); + int libc_reentrant; /* do we think we are reentrant? */ struct _reent libc_global_reent; @@ -196,6 +198,26 @@ rtems_extension libc_begin_hook(rtems_tcb *current_task) * */ +int newlib_free_buffers( + FILE *fp +) +{ + switch ( fileno(fp) ) { + case 0: + case 1: + case 2: + if (fp->_flags & __SMBF) { + free( fp->_bf._base ); + fp->_flags &= ~__SMBF; + fp->_bf._base = fp->_p = (unsigned char *) NULL; + } + break; + default: + fclose(fp); + } + return 0; +} + rtems_extension libc_delete_hook( rtems_tcb *current_task, rtems_tcb *deleted_task @@ -215,8 +237,14 @@ rtems_extension libc_delete_hook( /* if (ptr) */ if (ptr && ptr != &libc_global_reent) { +/* _wrapup_reent(ptr); _reclaim_reent(ptr); +*/ + /* + * Just in case there are some buffers lying around. + */ + _fwalk(ptr, newlib_free_buffers); #if REENT_MALLOCED free(ptr); #else -- cgit v1.2.3