public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug stdio/31838] New: There seems to be a memory leak bug in the fdopen function
@ 2024-06-03 12:46 simonzgx at gmail dot com
  2024-06-03 14:41 ` [Bug stdio/31838] " schwab@linux-m68k.org
  2024-06-03 14:44 ` schwab@linux-m68k.org
  0 siblings, 2 replies; 3+ messages in thread
From: simonzgx at gmail dot com @ 2024-06-03 12:46 UTC (permalink / raw)
  To: glibc-bugs

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

            Bug ID: 31838
           Summary: There seems to be a memory leak bug in the fdopen
                    function
           Product: glibc
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: stdio
          Assignee: unassigned at sourceware dot org
          Reporter: simonzgx at gmail dot com
  Target Milestone: ---

As shown in the ``libio/iofdopen.c``

FILE *
_IO_new_fdopen (int fd, const char *mode)
{
  int read_write;
  struct locked_FILE
  {
    struct _IO_FILE_plus fp;
#ifdef _IO_MTSAFE_IO
    _IO_lock_t lock;
#endif
    struct _IO_wide_data wd;
  } *new_f;

  // some code is omitted here
  new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
  if (new_f == NULL)
    return NULL;
        // some code is omitted here
  if (do_seek && ((read_write & (_IO_IS_APPENDING | _IO_NO_READS))
                  == (_IO_IS_APPENDING | _IO_NO_READS)))
    {
      off64_t new_pos = _IO_SYSSEEK (&new_f->fp.file, 0, _IO_seek_end);
      if (new_pos == _IO_pos_BAD && errno != ESPIPE)
      // should call free(new_f) to release memory here
        return NULL;
    }
  return &new_f->fp.file;
}


When the ``_IO_SYSSEEK`` returns an unexpected value, we forget to call
free(new_f) to free memory.

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug stdio/31838] There seems to be a memory leak bug in the fdopen function
  2024-06-03 12:46 [Bug stdio/31838] New: There seems to be a memory leak bug in the fdopen function simonzgx at gmail dot com
@ 2024-06-03 14:41 ` schwab@linux-m68k.org
  2024-06-03 14:44 ` schwab@linux-m68k.org
  1 sibling, 0 replies; 3+ messages in thread
From: schwab@linux-m68k.org @ 2024-06-03 14:41 UTC (permalink / raw)
  To: glibc-bugs

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

--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> ---
_IO_new_file_init_internal links the file to the global file list, so this
needs to unlink it first.

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug stdio/31838] There seems to be a memory leak bug in the fdopen function
  2024-06-03 12:46 [Bug stdio/31838] New: There seems to be a memory leak bug in the fdopen function simonzgx at gmail dot com
  2024-06-03 14:41 ` [Bug stdio/31838] " schwab@linux-m68k.org
@ 2024-06-03 14:44 ` schwab@linux-m68k.org
  1 sibling, 0 replies; 3+ messages in thread
From: schwab@linux-m68k.org @ 2024-06-03 14:44 UTC (permalink / raw)
  To: glibc-bugs

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

Andreas Schwab <schwab@linux-m68k.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #2 from Andreas Schwab <schwab@linux-m68k.org> ---
PR31840 has more details.

*** This bug has been marked as a duplicate of bug 31840 ***

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-06-03 14:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-03 12:46 [Bug stdio/31838] New: There seems to be a memory leak bug in the fdopen function simonzgx at gmail dot com
2024-06-03 14:41 ` [Bug stdio/31838] " schwab@linux-m68k.org
2024-06-03 14:44 ` schwab@linux-m68k.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).