public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "werner_hahn at yahoo dot de" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sources.redhat.com
Subject: [Bug libc/5666] New: when getline fails it still allocates a buffer
Date: Thu, 24 Jan 2008 21:00:00 -0000	[thread overview]
Message-ID: <20080124205922.5666.werner_hahn@yahoo.de> (raw)

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.


             reply	other threads:[~2008-01-24 21:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-24 21:00 werner_hahn at yahoo dot de [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080124205922.5666.werner_hahn@yahoo.de \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).