diff --git a/newlib/libc/tinystdio/bufio.c b/newlib/libc/tinystdio/bufio.c index 467a311a9a..af769e6e85 100644 --- a/newlib/libc/tinystdio/bufio.c +++ b/newlib/libc/tinystdio/bufio.c @@ -307,7 +307,10 @@ __bufio_close(FILE *f) /* Don't close stdin/stdout/stderr fds */ if (bf->fd > 2) (bf->close)(bf->fd); - free(f); + + /* Don't free memory if the stream is stdin/stdout/stderr */ + if ((f != stdin) && (f != stdout) && (f != stderr)) + free(f); return ret; }