aboutsummaryrefslogtreecommitdiff
path: root/libio/iofdopen.c
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@suse.de>2024-06-04 11:01:11 +0200
committerAndreas Schwab <schwab@suse.de>2024-06-04 14:42:06 +0200
commitb2c3ee3724900975deaf5eae57640bb0c2d7315e (patch)
treec750d128eabe728ccae047d05bbf0c66f40d0c7c /libio/iofdopen.c
parent1d441791cbea02b0261579f0332a7a85c21e2a3f (diff)
downloadglibc-b2c3ee3724900975deaf5eae57640bb0c2d7315e.zip
glibc-b2c3ee3724900975deaf5eae57640bb0c2d7315e.tar.gz
glibc-b2c3ee3724900975deaf5eae57640bb0c2d7315e.tar.bz2
Remove memory leak in fdopen (bug 31840)
Deallocate the memory for the FILE structure when seeking to the end fails in append mode. Fixes: ea33158c96 ("Fix offset caching for streams and use it for ftell (BZ #16680)")
Diffstat (limited to 'libio/iofdopen.c')
-rw-r--r--libio/iofdopen.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/libio/iofdopen.c b/libio/iofdopen.c
index 2583fb8..14fbc7b 100644
--- a/libio/iofdopen.c
+++ b/libio/iofdopen.c
@@ -156,7 +156,11 @@ _IO_new_fdopen (int fd, const char *mode)
{
off64_t new_pos = _IO_SYSSEEK (&new_f->fp.file, 0, _IO_seek_end);
if (new_pos == _IO_pos_BAD && errno != ESPIPE)
- return NULL;
+ {
+ _IO_un_link (&new_f->fp);
+ free (new_f);
+ return NULL;
+ }
}
return &new_f->fp.file;
}