]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Remove memory leak in fdopen (bug 31840)
authorAndreas Schwab <schwab@suse.de>
Tue, 4 Jun 2024 09:01:11 +0000 (11:01 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Fri, 15 Aug 2025 17:31:08 +0000 (19:31 +0200)
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)

NEWS
libio/iofdopen.c

diff --git a/NEWS b/NEWS
index ff361d6ff92557c905259421aeaf84fd93839eca..39221d7fbd3e76153cfa6c1ae8d26cf869bbbb9b 100644 (file)
--- 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 /
index 2583fb825573aae4db6600a028d93b28b0b17910..14fbc7b257ad77242c245cedaeb34feb4f791fa2 100644 (file)
@@ -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;
 }