[Bug stdio/31840] New: Memory leak in _IO_new_fdopen (fdopen) on seek failure

abbotti at mev dot co.uk sourceware-bugzilla@sourceware.org
Mon Jun 3 13:20:29 GMT 2024


https://sourceware.org/bugzilla/show_bug.cgi?id=31840

            Bug ID: 31840
           Summary: Memory leak in _IO_new_fdopen (fdopen) on seek failure
           Product: glibc
           Version: 2.38
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: stdio
          Assignee: unassigned at sourceware dot org
          Reporter: abbotti at mev dot co.uk
  Target Milestone: ---

Created attachment 15554
  --> https://sourceware.org/bugzilla/attachment.cgi?id=15554&action=edit
Test program dev-mem-append

If `_IO_new_fdopen` needs to seek to end of the file and the seek fails with an
error other than `ESPIPE`, `_IO_new_fdopen` returns `NULL` without freeing the
`struct locked_FILE` structure that was allocated by `malloc`, leading to a
memory leak.

On Linux with /dev/mem support in the kernel, this bug can be exercised by
opening a file descriptor to "/dev/mem" in `O_RDWR` mode (this requires
superuser rights), and calling `fdopen` on the file descriptor in append mode
"a". Since the underlying file does not support seeking to the end of the file,
this will fail with `errno` set to `EINVAL`. A leak detector such as Valgrind
can detect the leak, although for some reason the block is marked as "still
reachable".

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Glibc-bugs mailing list