This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug stdio/19464] New: getdelim leaks line when n is zero
- From: "msebor at redhat dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Thu, 14 Jan 2016 03:11:43 +0000
- Subject: [Bug stdio/19464] New: getdelim leaks line when n is zero
- Auto-submitted: auto-generated
https://sourceware.org/bugzilla/show_bug.cgi?id=19464
Bug ID: 19464
Summary: getdelim leaks line when n is zero
Product: glibc
Version: 2.23
Status: NEW
Severity: normal
Priority: P2
Component: stdio
Assignee: unassigned at sourceware dot org
Reporter: msebor at redhat dot com
Target Milestone: ---
Created attachment 8901
--> https://sourceware.org/bugzilla/attachment.cgi?id=8901&action=edit
Test case.
When called with a non-null *lineptr argument but *n zero, the getdelim (and
getline) functions set the *lineptr pointer to point at a newly allocated block
without freeing the previous block first. This results in the originally
allocated block leaking.
When linked against current glibc, the attached test case produces the
following output:
fopen("/usr/include/errno.h", "r")
malloc(560) ==> 0x604100
malloc(1248) ==> 0x604330
getdelim(&0x604330, &0)
malloc(128) ==> 0x604810
malloc(4096) ==> 0x604890
realloc(0x604810, 2368) ==> 0x605890
==> 2367 (Success)
free(0x605890)
getdelim leaked initally allocated block 0x604330
Compiling the test program with -DDO_NOT_REPLACE_MALLOC=1 and running it under
valgrind includes the following in the output:
==30160== HEAP SUMMARY:
==30160== in use at exit: 1,786 bytes in 2 blocks
==30160== total heap usage: 6 allocs, 4 frees, 9,394 bytes allocated
==30160==
==30160== 1,234 bytes in 1 blocks are definitely lost in loss record 2 of 2
==30160== at 0x4A06BCF: malloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==30160== by 0x4007D9: main (in
/home/msebor/build/glibc-trunk/libio/tst-getdelim)
--
You are receiving this mail because:
You are on the CC list for the bug.