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
|
|
|
42 | 42 | |
43 | 43 | #include <stdio.h> |
44 | 44 | |
| 45 | int _fwalk(struct _reent *ptr, int (*function) (FILE *) ); |
| 46 | |
45 | 47 | int libc_reentrant; /* do we think we are reentrant? */ |
46 | 48 | struct _reent libc_global_reent; |
47 | 49 | |
… |
… |
|
196 | 198 | * |
197 | 199 | */ |
198 | 200 | |
| 201 | int 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 | |
199 | 221 | rtems_extension libc_delete_hook( |
200 | 222 | rtems_tcb *current_task, |
201 | 223 | rtems_tcb *deleted_task |
… |
… |
|
215 | 237 | |
216 | 238 | /* if (ptr) */ |
217 | 239 | if (ptr && ptr != &libc_global_reent) { |
| 240 | /* |
218 | 241 | _wrapup_reent(ptr); |
219 | 242 | _reclaim_reent(ptr); |
| 243 | */ |
| 244 | /* |
| 245 | * Just in case there are some buffers lying around. |
| 246 | */ |
| 247 | _fwalk(ptr, newlib_free_buffers); |
220 | 248 | #if REENT_MALLOCED |
221 | 249 | free(ptr); |
222 | 250 | #else |