diff --git a/headers/posix/stdio.h b/headers/posix/stdio.h
index 73a74a8768..e0d395d218 100644
--- a/headers/posix/stdio.h
+++ b/headers/posix/stdio.h
@@ -120,7 +120,6 @@ extern FILE *fopencookie(void *cookie, const char *mode, cookie_io_functions_t
/* file I/O */
extern int fflush(FILE *stream);
extern int fflush_unlocked(FILE *stream);
-extern int fpurge(FILE *stream);
extern int fgetpos(FILE *stream, fpos_t *position);
extern int fsetpos(FILE *stream, const fpos_t *position);
diff --git a/src/system/libroot/posix/glibc/libio/__fpurge.c b/src/system/libroot/posix/glibc/libio/__fpurge.c
index 68217c8769..b167343561 100644
--- a/src/system/libroot/posix/glibc/libio/__fpurge.c
+++ b/src/system/libroot/posix/glibc/libio/__fpurge.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2014 Free Software Foundation, Inc.
+/* Copyright (C) 2000, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -12,9 +12,11 @@
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- . */
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+#include
#include
#include "libioP.h"
@@ -25,7 +27,7 @@ __fpurge (FILE *fp)
{
/* Wide-char stream. */
if (_IO_in_backup (fp))
- _IO_free_wbackup_area (fp);
+ INTUSE(_IO_free_wbackup_area) (fp);
fp->_wide_data->_IO_read_end = fp->_wide_data->_IO_read_ptr;
fp->_wide_data->_IO_write_ptr = fp->_wide_data->_IO_write_base;
@@ -34,16 +36,23 @@ __fpurge (FILE *fp)
{
/* Byte stream. */
if (_IO_in_backup (fp))
- _IO_free_backup_area (fp);
+ INTUSE(_IO_free_backup_area) (fp);
fp->_IO_read_end = fp->_IO_read_ptr;
fp->_IO_write_ptr = fp->_IO_write_base;
}
+
+ /* Avoid memory leak when there is an active ungetc buffer. */
+ if (fp->_IO_save_base != NULL)
+ {
+ free (fp->_IO_save_base);
+ fp->_IO_save_base = NULL;
+ }
}
int
fpurge(FILE* stream)
{
- __fpurge(stream);
- return 0;
+ __fpurge(stream);
+ return 0;
}