Ticket #524: pr524.diff

File pr524.diff, 1.4 KB (added by Joel Sherrill, on 12/03/06 at 13:31:12)

pr524.diff

  • src/newlibc.c

    2003-11-26	Joel Sherrill <joel@OARcorp.com>
    
    	PR 524/filesystem
    	* src/newlibc.c: Address 1K buffer leak from incomplete cleanup of
    	newlib reentrancy handler.
    
    RCS file: /usr1/CVS/rtems/cpukit/libcsupport/src/newlibc.c,v
    retrieving revision 1.42.2.5
    diff -u -r1.42.2.5 newlibc.c
     
    4242 
    4343#include <stdio.h>
    4444
     45int _fwalk(struct _reent *ptr, int (*function) (FILE *) );
     46
    4547int              libc_reentrant;        /* do we think we are reentrant? */
    4648struct _reent    libc_global_reent;
    4749
     
    196198 *
    197199 */
    198200
     201int newlib_free_buffers(
     202  FILE *fp
     203)
     204{
     205  switch ( fileno(fp) ) {
     206    case 0:
     207    case 1:
     208    case 2:
     209      if (fp->_flags & __SMBF) {
     210        free( fp->_bf._base );
     211        fp->_flags &= ~__SMBF;
     212        fp->_bf._base = fp->_p = (unsigned char *) NULL;
     213      }
     214      break;
     215    default:
     216     fclose(fp);
     217  }
     218  return 0;
     219}
     220
    199221rtems_extension libc_delete_hook(
    200222  rtems_tcb *current_task,
    201223  rtems_tcb *deleted_task
     
    215237
    216238  /* if (ptr) */
    217239  if (ptr && ptr != &libc_global_reent) {
     240/*
    218241    _wrapup_reent(ptr);
    219242    _reclaim_reent(ptr);
     243*/
     244    /*
     245     *  Just in case there are some buffers lying around.
     246     */
     247    _fwalk(ptr, newlib_free_buffers);
    220248#if REENT_MALLOCED
    221249    free(ptr);
    222250#else