public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/5666] New: when getline fails it still allocates a buffer
@ 2008-01-24 21:00 werner_hahn at yahoo dot de
  2008-01-24 21:04 ` [Bug libc/5666] " drepper at redhat dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: werner_hahn at yahoo dot de @ 2008-01-24 21:00 UTC (permalink / raw)
  To: glibc-bugs

This may be a documentation issue.

When passing the getline function a NULL pointer as a buffer it is so kind to 
allocate the needed memory. However when you reach for example EOF and the 
function returns -1 a buffer of length 120 bytes is allocated anyway which must 
be freed manually or else is lost. It took me quite some time to find out why 
valgrind always told me of 120 lost bytes. The documentation does not mention 
this and so I never suspected this function to be the memory leak.

As getline just functions as a wrapper around getdelim the issue should apply 
to that as well.

I give a quick example:

char *line = NULL;
unsigned int count = 0;
count = getline(&line, &count, file_descriptor);
if(count == -1) // now line points to 120 bytes of junk
{
  free(line); // without this free the buffer pointed to by line is lost
  return NULL;
}

-- 
           Summary: when getline fails it still allocates a buffer
           Product: glibc
           Version: 2.3.6
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: werner_hahn at yahoo dot de
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=5666

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

end of thread, other threads:[~2014-07-02  7:45 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-5666-131@http.sourceware.org/bugzilla/>
2011-12-09 16:18 ` [Bug libc/5666] when getline fails it still allocates a buffer svoboda at cert dot org
2011-12-18  1:47 ` drepper.fsp at gmail dot com
2012-01-03 21:32 ` svoboda at cert dot org
2014-04-02  9:26 ` vapier at gentoo dot org
2014-04-03 22:24 ` cvs-commit at gcc dot gnu.org
2014-04-03 22:24 ` vapier at gentoo dot org
2014-07-02  7:45 ` fweimer at redhat dot com
2008-01-24 21:00 [Bug libc/5666] New: " werner_hahn at yahoo dot de
2008-01-24 21:04 ` [Bug libc/5666] " drepper at redhat dot com
2008-01-25  9:33 ` werner_hahn at yahoo dot de
2008-03-04 18:35 ` drepper at redhat dot com

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).