From: Andreas Schwab Date: Tue, 4 Jun 2024 09:01:11 +0000 (+0200) Subject: Remove memory leak in fdopen (bug 31840) X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=42a8cb756064ee71f687f07cd57cc92e831e770e;p=thirdparty%2Fglibc.git 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)") (cherry picked from commit b2c3ee3724900975deaf5eae57640bb0c2d7315e) --- diff --git a/NEWS b/NEWS index ff361d6ff9..39221d7fbd 100644 --- a/NEWS +++ b/NEWS @@ -87,6 +87,7 @@ The following bugs are resolved with this release: (x86/tst-cpu-features-supports.c:69:3: error: parameter to builtin not valid: avx5124fmaps) [31798] pidfd_getpid.c is miscompiled by GCC 6.4 + [31840] Remove memory leak in fdopen [31867] build: "CPU ISA level is lower than required" on SSE2-free CPUs [31883] build: ISA level support configure check relies on bashism / diff --git a/libio/iofdopen.c b/libio/iofdopen.c index 2583fb8255..14fbc7b257 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; }