]> 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)
committerAndreas Schwab <schwab@suse.de>
Tue, 4 Jun 2024 12:42:06 +0000 (14:42 +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)")
libio/iofdopen.c

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;
 }