Releasing stdout/stdin/stderr descriptors when a task/process finishes

Martin Velek
Thu Aug 13 11:50:00 GMT 2015


how are the stdout/stdin/stderr descriptors freed when a task/process
finishes? I am using FreeRTOS with newlib support and when the task
finishes its job the _reclaim_reent is called. The stdio cleanup is
called because ptr->__sdidinit != 0, it will walk it with
_fwalk_reent (ptr, _fclose_r). However in the for-cycle a function
pointer to _fclose_r command (_fwalk_reent) is never called because
the g->_niobs = 0. It leaves stdout/stdin/stderr with flags fp->_flags
!= 0 which means the descriptor is not free.

Manual close by fclose (stdout/stdin/stderr ) before the task finishes
is possible but I would prefer an implicit(do not care about it) way.

Here is a pseudo example:

#include <rtos support>
#include <stdio.h>
Task A
char buff[20];


I have compiled the newlib 2.2.0 with these parameters:

 ./configure --target=arm-none-eabi --disable-newlib-supplied-syscalls
--enable-newlib-io-long-long --enable-newlib-reent-small
--disable-libgloss --enable-newlib-io-c99-formats
--disable-newlib-atexit-dynamic-alloc --enable-newlib-global-atexit
--enable-newlib-reent-small --disable-newlib-wide-orient
--disable-multilib --enable-newlib-multithread
--disable-newlib-register-fini --disable-newlib-mb
--disable-newlib-unbuf-stream-opt --disable-newlib-fvwrite-in-streamio

-fstack-usage -ffunction-sections -fdata-sections -Wstack-usage=512
-mcpu=cortex-m3 -mthumb -std=gnu11 -fno-common -g3"

arm-none-eabi-gcc -v
gcc version 4.9.3 20150303 (release) [ARM/embedded-4_9-branch revision
221220] (GNU Tools for ARM Embedded Processors)

More information about the Newlib mailing list