From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9034 invoked by alias); 24 Jan 2008 21:00:05 -0000 Received: (qmail 8657 invoked by uid 48); 24 Jan 2008 20:59:23 -0000 Date: Thu, 24 Jan 2008 21:00:00 -0000 From: "werner_hahn at yahoo dot de" To: glibc-bugs@sources.redhat.com Message-ID: <20080124205922.5666.werner_hahn@yahoo.de> Reply-To: sourceware-bugzilla@sourceware.org Subject: [Bug libc/5666] New: when getline fails it still allocates a buffer X-Bugzilla-Reason: CC Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org X-SW-Source: 2008-01/txt/msg00080.txt.bz2 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.