glibc/glibc-RHEL-108475-1.patch
Frédéric Bérat d19eb70013 Fix memory leak after fdopen seek failure
- Backport: Remove memory leak in fdopen (bug 31840)
- Backport: libio: Test for fdopen memory leak without SEEK_END
  support (bug 31840)

Resolves: RHEL-108475
2025-08-11 14:28:18 +02:00

29 lines
837 B
Diff

commit b2c3ee3724900975deaf5eae57640bb0c2d7315e
Author: Andreas Schwab <schwab@suse.de>
Date: Tue Jun 4 11:01:11 2024 +0200
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)")
diff --git a/libio/iofdopen.c b/libio/iofdopen.c
index 2583fb825573aae4..14fbc7b257ad7724 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;
}