[PATCH] Fix stdio memory leaks with _REENT_SMALL + _LITE_EXIT

Volodymyr Medvid vmmedvid@gmail.com
Tue Apr 12 20:57:01 GMT 2022

On Tue, 12 Apr 2022 18:10:38 +0200
Sebastian Huber <sebastian.huber@embedded-brains.de> wrote:

> This is definitely not the right way to address this issue.
> Why don't you use the _REENT_GLOBAL_STDIO_STREAMS Newlib
> configuration option?

Thanks for the suggestion - I was able to verify the memory leak goes away once
newlib-nano is reconfigured with "--enable-newlib-global-stdio-streams".
I also see you originally submitted commit
that was later extended to also apply to _REENT_SMALL
I filed a ticket https://bugs.linaro.org/show_bug.cgi?id=5841 to
enable global stdio
streams for standard newlib-nano provided with GNU Arm Embedded
toolchain binary package.

> This patch would break at least RTEMS.

Sorry, I have no way to validate this on any platform except Arm
Cortex-M + FreeRTOS.
Also, the current test suite is not capable of catching issues with
stdio reentrancy.
I understand there are lot of platform/OS-specific stdio
implementations, some of them
may rely on configure flags like "--enable-newlib-reent-small" or
to meet the memory and performance constraints. Unfortunately, it is
not clear from
the commit e7565f10886bac86410db6eb6fda47da1d04ac9b why _fclose_r was changed to
_fflush_r when _LITE_EXIT is enabled - is this to reduce memory footprint?


More information about the Newlib mailing list