From nobody@FreeBSD.org  Thu Jun 15 08:55:07 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 7511716A4C9
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 15 Jun 2006 08:55:07 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 0B89643D45
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 15 Jun 2006 08:55:07 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k5F8t6D7009612
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 15 Jun 2006 08:55:06 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k5F8t6WO009611;
	Thu, 15 Jun 2006 08:55:06 GMT
	(envelope-from nobody)
Message-Id: <200606150855.k5F8t6WO009611@www.freebsd.org>
Date: Thu, 15 Jun 2006 08:55:06 GMT
From: Matt <freebsdbugs@fjarlq.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: ncurses: tgetent leaks nearly 10 KB of memory every time it is called
X-Send-Pr-Version: www-2.3
X-GNATS-Notify: freebsdbugs@fjarlq.com

>Number:         98975
>Category:       gnu
>Synopsis:       ncurses: tgetent leaks nearly 10 KB of memory every time it is called
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    rafan
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 15 09:00:35 GMT 2006
>Closed-Date:    Tue Jul 01 09:29:23 UTC 2008
>Last-Modified:  Tue Jul 01 09:29:23 UTC 2008
>Originator:     Matt
>Release:        6.1-RELEASE
>Organization:
>Environment:
Observed on both amd64 and i386. Here's my cc -v for the demo program
below:

% cc -v tgetentloop.c -o tgetentloop -ltinfo
Using built-in specs.
Configured with: FreeBSD/amd64 system compiler
Thread model: posix
gcc version 3.4.4 [FreeBSD] 20050518
 /usr/libexec/cc1 -quiet -v -D_LONGLONG tgetentloop.c -quiet -dumpbase tgetentloop.c -auxbase tgetentloop -version -o /var/tmp//ccdB95Tg.s
ignoring duplicate directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include
End of search list.
GNU C version 3.4.4 [FreeBSD] 20050518 (amd64-undermydesk-freebsd)
        compiled by GNU C version 3.4.4 [FreeBSD] 20050518.
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
 /usr/bin/as -V -Qy -o /var/tmp//ccQbQvZT.o /var/tmp//ccdB95Tg.s
GNU assembler version 2.15 [FreeBSD] 2004-05-23 (x86_64-obrien-freebsd) using BFD version 2.15 [FreeBSD] 2004-05-23
 /usr/bin/ld -V -dynamic-linker /libexec/ld-elf.so.1 -o tgetentloop /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib /var/tmp//ccQbQvZT.o -ltinfo -lgcc -lc -lgcc /usr/lib/crtend.o /usr/lib/crtn.o
GNU ld version 2.15 [FreeBSD] 2004-05-23
  Supported emulations:
   elf_i386_fbsd
   elf_x86_64_fbsd
>Description:
This program demonstrates a large memory leak in tgetent:

#include <termcap.h>
#include <unistd.h>
int
main()
{
    while (1) {
        tgetent(NULL, "vt100");
        write(1, ".", 1);
        usleep(5000);
    }
}

Compile with this command:
  cc tgetentloop.c -o tgetentloop -ltinfo

Run it and watch the memory size grow with "top". This leaks about 3
MB/sec on my amd64 system. 1,000 calls to tgetent consistently leak
9,660 KB, so about 10 KB/call.

>How-To-Repeat:
No, I don't need to call tgetent 200 times per second :), but this
leak is actually affecting me in a significant way. I have a FreeBSD
server where many users run long-running programs from within GNU screen
version 4.0.2. Every time they attach to their GNU screen session,
tgetent() gets called (several times per reattach, I believe).

I've been keeping daily process memory usage stats for a couple years
on this server. The last time I restarted my screen (which is painful,
requiring me to restart all the programs inside it) was December 6,
2005; on that day my screen was using 6,088 KB. On June 15, 2006 that
same screen process was using 83,456 KB. This was one of the major
memory leaks that caused my system to run out of swap space a few months
ago. Periodically my users have to restart their screen sessions to
relinquish the leaked memory.

I studied the problem for a few hours using ccmalloc to catch memory
leaks in screen, and I don't think this is the only memory leak in GNU
screen, but it is by far the most serious.

>Fix:
The bug exists in the ncurses version 5.2-20020615 code that ships with
FreeBSD 6.1-RELEASE. The leak seems to be almost entirely fixed in
ncurses 5.5:

1) Install ncurses 5.5 from /usr/ports/devel/ncurses
2) Link above program with it using this command:
     cc tgetentloop.c -o tgetentloop -static -L/usr/local/lib -ltinfo
3) Run tgetentloop and observe that it only grows 4 KB/sec on amd64
   instead of 3 MB/sec as with the stock FreeBSD libtinfo.

So there's still a really tiny leak somewhere in there, sigh.
>Release-Note:
>Audit-Trail:

From: Matt <freebsdbugs@fjarlq.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: gnu/98975: ncurses: tgetent leaks nearly 10 KB of memory every time it is called
Date: Thu, 15 Jun 2006 02:37:53 -0700

 Argh, sorry, I didn't realize that I needed to insert hard returns
 to wrap my paragraphs properly, even though that's documented in
 the bug submission procedure. I would be happy to resubmit if that
 would be preferable, please let me know.
 Matt


From: Matt <freebsdbugs@fjarlq.com>
To: bug-followup@FreeBSD.org
Cc: bug-ncurses@gnu.org, screen-devel@gnu.org
Subject: Re: gnu/98975: ncurses: tgetent leaks nearly 10 KB of memory every time it is called
Date: Sat, 17 Jun 2006 14:58:34 -0700

 FreeBSD bug report: http://www.freebsd.org/cgi/query-pr.cgi?pr=98975
 
 Dear FreeBSD, GNU ncurses, and GNU screen folks,
 
 I wrote earlier that the 10 KB per call memory leak in tgetent seems
 to be fixed in ncurses version 5.5. That's still true, however I
 have since learned that the leak is only fixed if tgetent is called
 with the same terminal name each time. If the terminal name changes,
 for example alternating tgetent calls for "vt100" and "sun", it
 leaks memory, again about 10 KB per call.
 
 Unfortunately that is exactly how GNU screen uses tgetent. Every
 time a user reattaches to their running GNU screen session, it calls
 tgetent for $TERM and then calls tgetent again for the "screen"
 terminal. This forces my users to restart their long-running screen
 sessions periodically, due to all the screen processes each growing
 several megabytes per month.
 
 Here's how to reproduce this leak on FreeBSD:
 
 1) Install ncurses 5.5 from /usr/ports/devel/ncurses
 2) Compile the following program with it using this command:
      cc tgetentaltloop.c -o tgetentaltloop -static -L/usr/local/lib -ltinfo
 
 #include <termcap.h>
 #include <unistd.h>
 int
 main()
 {
     while (1) {
         tgetent(NULL, "vt100");
         tgetent(NULL, "sun");
         write(1, ".", 1);
         usleep(5000);
     }
 }
 
 3) Run tgetentaltloop and observe (using "ps" or "top") that it
    grows in size about 3 MB per second.
 
 This is using ncurses 5.5 as built by FreeBSD ports/devel/ncurses
 with their Makefile revision 1.36:
 http://www.freebsd.org/cgi/cvsweb.cgi/ports/devel/ncurses/
 
 To help identify the leak, I modified the above program to loop 100
 times instead of forever, like so:
 
 #include <termcap.h>
 #include <unistd.h>
 int
 main()
 {
     int x;
     for (x = 0; x < 100; x++) {
         tgetent(NULL, "vt100");
         tgetent(NULL, "sun");
         write(1, ".", 1);
         usleep(5000);
     }
 } 
 
 and then linked it with the ccmalloc library. Here's the report:
 
 .--------------------------------------------------------------------------.
 |================ ccmalloc-0.4.0 (C) 1997-2003 Armin Biere ================|
 +--------------------------------------------------------------------------+
 | executable       = /home/user/tgetentaltloop                             |
 | startup file     = .ccmalloc                                             |
 | log file         = /home/user/tgetentdbg/log.95456                       |
 | start time       = Sat Jun 17 14:44:40 2006                              |
 | operating system = FreeBSD 6.1-RELEASE amd64 on example.com              |
 +--------------------------------------------------------------------------+
 | only-count        = 0            keep-deallocated-data = 0               |
 | check-interval    = 0            check-free-space      = 0               |
 | check-start       = 0            file-info             = 1               |
 | chain-length      = 0            additional-line       = 1               |
 | check-underwrites = 0            print-addresses       = 0               |
 | check-overwrites  = 0            print-on-one-line     = 0               |
 | sort-by-wasted    = 1            sort-by-size          = 1               |
 | # only-log-chain  = 0            continue              = 0               |
 | # dont-log-chain  = 0            statistics            = 0               |
 | debug             = 0            library-chains        = 0               |
 | load-dynlibs      = 1            align-8-byte          = 0               |
 | only-wasting-alloc= 1                                                    |
 `--------------------------------------------------------------------------'
 
 .---------------.
 |ccmalloc report|
 =======================================================
 | total # of|   allocated | deallocated |     garbage |
 +-----------+-------------+-------------+-------------+
 |      bytes|      829522 |        9508 |      820014 |
 +-----------+-------------+-------------+-------------+
 |allocations|        2205 |         702 |        1503 |
 +-----------------------------------------------------+
 | number of checks: 1                                 |
 | number of counts: 2907                              |
 | retrieving function names for addresses ... done.   |
 | reading file info from gdb ... done.                |
 | sorting by number of not reclaimed bytes ... done.  |
 | number of call chains: 15                           |
 | number of ignored call chains: 0                    |
 | number of reported call chains: 15                  |
 | number of internal call chains: 15                  |
 | number of library call chains: 1                    |
 =======================================================
 |
 * 40.4% = 323.4 KB of garbage allocated in 100 allocations
 |       |
 |       |       0x00402034 in <main>
 |       |                  at tgetentaltloop.c:8
 |       |
 |       |       0x00402098 in <tgetent>
 |       |                  at ../../ncurses/tinfo/lib_termcap.c:77
 |       |
 |       |       0x00404556 in <_nc_setupterm>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:484
 |       |
 |       |       0x00403fd9 in <grab_entry>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:276
 |       |
 |       |       0x004070d8 in <_nc_read_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:514
 |       |
 |       |       0x00406ef2 in <_nc_read_terminfo_dirs>
 |       |                  at ../../ncurses/tinfo/read_entry.c:444
 |       |
 |       |       0x00406e51 in <_nc_read_tic_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:419
 |       |
 |       |       0x00406dbc in <_nc_read_file_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:397
 |       |
 |       |       0x004066af in <read_termtype>
 |       |                  at ../../ncurses/tinfo/read_entry.c:239
 |       |
 |       |       0x004124e6 in <calloc>
 |       |
 |       `-----> 0x004123fe in <malloc>
 |        
 * 40.4% = 323.4 KB of garbage allocated in 100 allocations
 |       |
 |       |       0x00402043 in <main>
 |       |                  at tgetentaltloop.c:9
 |       |
 |       |       0x00402098 in <tgetent>
 |       |                  at ../../ncurses/tinfo/lib_termcap.c:77
 |       |
 |       |       0x00404556 in <_nc_setupterm>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:484
 |       |
 |       |       0x00403fd9 in <grab_entry>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:276
 |       |
 |       |       0x004070d8 in <_nc_read_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:514
 |       |
 |       |       0x00406ef2 in <_nc_read_terminfo_dirs>
 |       |                  at ../../ncurses/tinfo/read_entry.c:444
 |       |
 |       |       0x00406e51 in <_nc_read_tic_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:419
 |       |
 |       |       0x00406dbc in <_nc_read_file_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:397
 |       |
 |       |       0x004066af in <read_termtype>
 |       |                  at ../../ncurses/tinfo/read_entry.c:239
 |       |
 |       |       0x004124e6 in <calloc>
 |       |
 |       `-----> 0x004123fe in <malloc>
 |        
 |  6.7% = 53.3 KB of garbage allocated in 100 allocations
 |       |
 |       |       0x00402034 in <main>
 |       |                  at tgetentaltloop.c:8
 |       |
 |       |       0x00402098 in <tgetent>
 |       |                  at ../../ncurses/tinfo/lib_termcap.c:77
 |       |
 |       |       0x00404556 in <_nc_setupterm>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:484
 |       |
 |       |       0x00403fd9 in <grab_entry>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:276
 |       |
 |       |       0x004070d8 in <_nc_read_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:514
 |       |
 |       |       0x00406ef2 in <_nc_read_terminfo_dirs>
 |       |                  at ../../ncurses/tinfo/read_entry.c:444
 |       |
 |       |       0x00406e51 in <_nc_read_tic_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:419
 |       |
 |       |       0x00406dbc in <_nc_read_file_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:397
 |       |
 |       |       0x0040640c in <read_termtype>
 |       |                  at ../../ncurses/tinfo/read_entry.c:196
 |       |
 |       `-----> 0x004123fe in <malloc>
 |        
 |  3.8% = 30.6 KB of garbage allocated in 100 allocations
 |       |
 |       |       0x00402043 in <main>
 |       |                  at tgetentaltloop.c:9
 |       |
 |       |       0x00402098 in <tgetent>
 |       |                  at ../../ncurses/tinfo/lib_termcap.c:77
 |       |
 |       |       0x00404556 in <_nc_setupterm>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:484
 |       |
 |       |       0x00403fd9 in <grab_entry>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:276
 |       |
 |       |       0x004070d8 in <_nc_read_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:514
 |       |
 |       |       0x00406ef2 in <_nc_read_terminfo_dirs>
 |       |                  at ../../ncurses/tinfo/read_entry.c:444
 |       |
 |       |       0x00406e51 in <_nc_read_tic_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:419
 |       |
 |       |       0x00406dbc in <_nc_read_file_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:397
 |       |
 |       |       0x0040640c in <read_termtype>
 |       |                  at ../../ncurses/tinfo/read_entry.c:196
 |       |
 |       `-----> 0x004123fe in <malloc>
 |        
 |  2.1% = 17.2 KB of garbage allocated in 100 allocations
 |       |
 |       |       0x00402034 in <main>
 |       |                  at tgetentaltloop.c:8
 |       |
 |       |       0x00402098 in <tgetent>
 |       |                  at ../../ncurses/tinfo/lib_termcap.c:77
 |       |
 |       |       0x00404501 in <_nc_setupterm>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:477
 |       |
 |       |       0x004124e6 in <calloc>
 |       |
 |       `-----> 0x004123fe in <malloc>
 |        
 |  2.1% = 17.2 KB of garbage allocated in 100 allocations
 |       |
 |       |       0x00402043 in <main>
 |       |                  at tgetentaltloop.c:9
 |       |
 |       |       0x00402098 in <tgetent>
 |       |                  at ../../ncurses/tinfo/lib_termcap.c:77
 |       |
 |       |       0x00404501 in <_nc_setupterm>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:477
 |       |
 |       |       0x004124e6 in <calloc>
 |       |
 |       `-----> 0x004123fe in <malloc>
 |        
 |  0.10% = 7800 Bytes of garbage allocated in 100 allocations
 |       |
 |       |       0x00402034 in <main>
 |       |                  at tgetentaltloop.c:8
 |       |
 |       |       0x00402098 in <tgetent>
 |       |                  at ../../ncurses/tinfo/lib_termcap.c:77
 |       |
 |       |       0x00404556 in <_nc_setupterm>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:484
 |       |
 |       |       0x00403fd9 in <grab_entry>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:276
 |       |
 |       |       0x004070d8 in <_nc_read_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:514
 |       |
 |       |       0x00406ef2 in <_nc_read_terminfo_dirs>
 |       |                  at ../../ncurses/tinfo/read_entry.c:444
 |       |
 |       |       0x00406e51 in <_nc_read_tic_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:419
 |       |
 |       |       0x00406dbc in <_nc_read_file_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:397
 |       |
 |       |       0x0040660d in <read_termtype>
 |       |                  at ../../ncurses/tinfo/read_entry.c:233
 |       |
 |       |       0x004124e6 in <calloc>
 |       |
 |       `-----> 0x004123fe in <malloc>
 |        
 |  0.10% = 7800 Bytes of garbage allocated in 100 allocations
 |       |
 |       |       0x00402043 in <main>
 |       |                  at tgetentaltloop.c:9
 |       |
 |       |       0x00402098 in <tgetent>
 |       |                  at ../../ncurses/tinfo/lib_termcap.c:77
 |       |
 |       |       0x00404556 in <_nc_setupterm>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:484
 |       |
 |       |       0x00403fd9 in <grab_entry>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:276
 |       |
 |       |       0x004070d8 in <_nc_read_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:514
 |       |
 |       |       0x00406ef2 in <_nc_read_terminfo_dirs>
 |       |                  at ../../ncurses/tinfo/read_entry.c:444
 |       |
 |       |       0x00406e51 in <_nc_read_tic_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:419
 |       |
 |       |       0x00406dbc in <_nc_read_file_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:397
 |       |
 |       |       0x0040660d in <read_termtype>
 |       |                  at ../../ncurses/tinfo/read_entry.c:233
 |       |
 |       |       0x004124e6 in <calloc>
 |       |
 |       `-----> 0x004123fe in <malloc>
 |        
 |  0.7% = 5600 Bytes of garbage allocated in 100 allocations
 |       |
 |       |       0x00402043 in <main>
 |       |                  at tgetentaltloop.c:9
 |       |
 |       |       0x00402098 in <tgetent>
 |       |                  at ../../ncurses/tinfo/lib_termcap.c:77
 |       |
 |       |       0x00404556 in <_nc_setupterm>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:484
 |       |
 |       |       0x00403fd9 in <grab_entry>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:276
 |       |
 |       |       0x004070d8 in <_nc_read_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:514
 |       |
 |       |       0x00406ef2 in <_nc_read_terminfo_dirs>
 |       |                  at ../../ncurses/tinfo/read_entry.c:444
 |       |
 |       |       0x00406e51 in <_nc_read_tic_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:419
 |       |
 |       |       0x00406dbc in <_nc_read_file_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:397
 |       |
 |       |       0x004064dd in <read_termtype>
 |       |                  at ../../ncurses/tinfo/read_entry.c:210
 |       |
 |       |       0x004124e6 in <calloc>
 |       |
 |       `-----> 0x004123fe in <malloc>
 |        
 |  0.5% = 4400 Bytes of garbage allocated in 100 allocations
 |       |
 |       |       0x00402034 in <main>
 |       |                  at tgetentaltloop.c:8
 |       |
 |       |       0x00402098 in <tgetent>
 |       |                  at ../../ncurses/tinfo/lib_termcap.c:77
 |       |
 |       |       0x00404556 in <_nc_setupterm>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:484
 |       |
 |       |       0x00403fd9 in <grab_entry>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:276
 |       |
 |       |       0x004070d8 in <_nc_read_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:514
 |       |
 |       |       0x00406ef2 in <_nc_read_terminfo_dirs>
 |       |                  at ../../ncurses/tinfo/read_entry.c:444
 |       |
 |       |       0x00406e51 in <_nc_read_tic_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:419
 |       |
 |       |       0x00406dbc in <_nc_read_file_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:397
 |       |
 |       |       0x004064dd in <read_termtype>
 |       |                  at ../../ncurses/tinfo/read_entry.c:210
 |       |
 |       |       0x004124e6 in <calloc>
 |       |
 |       `-----> 0x004123fe in <malloc>
 |        
 |  0.5% = 4400 Bytes of garbage allocated in 100 allocations
 |       |
 |       |       0x00402034 in <main>
 |       |                  at tgetentaltloop.c:8
 |       |
 |       |       0x00402098 in <tgetent>
 |       |                  at ../../ncurses/tinfo/lib_termcap.c:77
 |       |
 |       |       0x00404556 in <_nc_setupterm>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:484
 |       |
 |       |       0x00403fd9 in <grab_entry>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:276
 |       |
 |       |       0x004070d8 in <_nc_read_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:514
 |       |
 |       |       0x00406ef2 in <_nc_read_terminfo_dirs>
 |       |                  at ../../ncurses/tinfo/read_entry.c:444
 |       |
 |       |       0x00406e51 in <_nc_read_tic_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:419
 |       |
 |       |       0x00406dbc in <_nc_read_file_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:397
 |       |
 |       |       0x00406569 in <read_termtype>
 |       |                  at ../../ncurses/tinfo/read_entry.c:219
 |       |
 |       |       0x004124e6 in <calloc>
 |       |
 |       `-----> 0x004123fe in <malloc>
 |        
 |  0.5% = 4400 Bytes of garbage allocated in 100 allocations
 |       |
 |       |       0x00402043 in <main>
 |       |                  at tgetentaltloop.c:9
 |       |
 |       |       0x00402098 in <tgetent>
 |       |                  at ../../ncurses/tinfo/lib_termcap.c:77
 |       |
 |       |       0x00404556 in <_nc_setupterm>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:484
 |       |
 |       |       0x00403fd9 in <grab_entry>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:276
 |       |
 |       |       0x004070d8 in <_nc_read_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:514
 |       |
 |       |       0x00406ef2 in <_nc_read_terminfo_dirs>
 |       |                  at ../../ncurses/tinfo/read_entry.c:444
 |       |
 |       |       0x00406e51 in <_nc_read_tic_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:419
 |       |
 |       |       0x00406dbc in <_nc_read_file_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:397
 |       |
 |       |       0x00406569 in <read_termtype>
 |       |                  at ../../ncurses/tinfo/read_entry.c:219
 |       |
 |       |       0x004124e6 in <calloc>
 |       |
 |       `-----> 0x004123fe in <malloc>
 |        
 |  0.0% = 77 Bytes of garbage allocated in 1 allocation
 |       |
 |       |       0x00402034 in <main>
 |       |                  at tgetentaltloop.c:8
 |       |
 |       |       0x004021f6 in <tgetent>
 |       |                  at ../../ncurses/tinfo/lib_termcap.c:99
 |       |
 |       |       0x004036d3 in <_nc_trim_sgr0>
 |       |                  at ../../ncurses/tinfo/trim_sgr0.c:236
 |       |
 |       |       0x00403114 in <set_attribute_9>
 |       |                  at ../../ncurses/tinfo/trim_sgr0.c:54
 |       |
 |       |       0x00404e17 in <tparm>
 |       |                  at ../../ncurses/tinfo/lib_tparm.c:788
 |       |
 |       |       0x00404e9e in <tparam_internal>
 |       |                  at ../../ncurses/tinfo/lib_tparm.c:502
 |       |
 |       |       0x00404880 in <_nc_tparm_analyze>
 |       |                  at ../../ncurses/tinfo/lib_tparm.c:374
 |       |
 |       |       0x0040788e in <_nc_doalloc>
 |       |                  at ../../ncurses/tinfo/doalloc.c:55
 |       |
 |       `-----> 0x004123fe in <malloc>
 |        
 |  0.0% = 23 Bytes of garbage allocated in 1 allocation
 |       |
 |       |       0x00402034 in <main>
 |       |                  at tgetentaltloop.c:8
 |       |
 |       |       0x00402098 in <tgetent>
 |       |                  at ../../ncurses/tinfo/lib_termcap.c:77
 |       |
 |       |       0x00404556 in <_nc_setupterm>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:484
 |       |
 |       |       0x00403fd9 in <grab_entry>
 |       |                  at ../../ncurses/tinfo/lib_setup.c:276
 |       |
 |       |       0x00407056 in <_nc_read_entry>
 |       |                  at ../../ncurses/tinfo/read_entry.c:498
 |       |
 |       |       0x00407ad3 in <_nc_home_terminfo>
 |       |                  at ../../ncurses/tinfo/home_terminfo.c:58
 |       |
 |       `-----> 0x004123fe in <malloc>
 |        
 |  0.0% = 14 Bytes of garbage allocated in 1 allocation
 |       |
 |       |       0x00402034 in <main>
 |       |                  at tgetentaltloop.c:8
 |       |
 |       |       0x004021f6 in <tgetent>
 |       |                  at ../../ncurses/tinfo/lib_termcap.c:99
 |       |
 |       |       0x004036d3 in <_nc_trim_sgr0>
 |       |                  at ../../ncurses/tinfo/trim_sgr0.c:236
 |       |
 |       |       0x00403114 in <set_attribute_9>
 |       |                  at ../../ncurses/tinfo/trim_sgr0.c:54
 |       |
 |       |       0x00404e17 in <tparm>
 |       |                  at ../../ncurses/tinfo/lib_tparm.c:788
 |       |
 |       |       0x00405099 in <tparam_internal>
 |       |                  at ../../ncurses/tinfo/lib_tparm.c:549
 |       |
 |       |       0x00405ae2 in <save_char>
 |       |                  at ../../ncurses/tinfo/lib_tparm.c:191
 |       |
 |       |       0x00405888 in <get_space>
 |       |                  at ../../ncurses/tinfo/lib_tparm.c:155
 |       |
 |       |       0x00407864 in <_nc_doalloc>
 |       |                  at ../../ncurses/tinfo/doalloc.c:50
 |       |
 |       |       0x0041267a in <realloc>
 |       |
 |       |       0x0041252d in <_realloc>
 |       |
 |       `-----> 0x004123fe in <malloc>
 |        
 `------------------------------------------------------

From: Thomas Dickey <dickey@his.com>
To: Matt <freebsdbugs@fjarlq.com>
Cc: bug-followup@FreeBSD.org, Ncurses Mailing List <bug-ncurses@gnu.org>,
        screen-devel@gnu.org
Subject: Re: gnu/98975: ncurses: tgetent leaks nearly 10 KB of memory every
 time it is called
Date: Sat, 17 Jun 2006 20:14:59 -0400 (EDT)

 On Sat, 17 Jun 2006, Matt wrote:
 
 > FreeBSD bug report: http://www.freebsd.org/cgi/query-pr.cgi?pr=98975
 >
 > Dear FreeBSD, GNU ncurses, and GNU screen folks,
 >
 > I wrote earlier that the 10 KB per call memory leak in tgetent seems
 > to be fixed in ncurses version 5.5. That's still true, however I
 > have since learned that the leak is only fixed if tgetent is called
 > with the same terminal name each time. If the terminal name changes,
 > for example alternating tgetent calls for "vt100" and "sun", it
 > leaks memory, again about 10 KB per call.
 
 ok - something for next week (I did some fixes for the small leaks today).
 
 -- 
 Thomas E. Dickey
 http://invisible-island.net
 ftp://invisible-island.net
Responsible-Changed-From-To: freebsd-bugs->rafan 
Responsible-Changed-By: rafan 
Responsible-Changed-When: Sat Dec 30 02:40:26 UTC 2006 
Responsible-Changed-Why:  
I'm working on a ncurses 5.6 port, which should fix this issue. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=98975 
State-Changed-From-To: open->feedback 
State-Changed-By: rafan 
State-Changed-When: Sun Dec 31 07:08:40 UTC 2006 
State-Changed-Why:  


http://www.freebsd.org/cgi/query-pr.cgi?pr=98975 

From: Thomas Dickey <dickey@his.com>
To: bug-followup@FreeBSD.org, freebsdbugs@fjarlq.com
Cc:  
Subject: gnu/98975
Date: Sat, 27 Jan 2007 19:41:03 -0500

 --SLDf9lqlvOQaIe6s
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Rong-en Fan pointed out that my fix didn't allow for null pointer in
 tgetent() params.  Since I was focused on fixing the problem for screen
 (which has to assume conventional termcap), I didn't notice that.
 There's a small fix in tonight's ncurses patch.
 
 --=20
 Thomas E. Dickey <dickey@invisible-island.net>
 http://invisible-island.net
 ftp://invisible-island.net
 
 --SLDf9lqlvOQaIe6s
 Content-Type: application/pgp-signature; name="signature.asc"
 Content-Description: Digital signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.6 (GNU/Linux)
 
 iD8DBQFFu/EfcCNT4PfkjtsRAtkHAJ0UIoAqoWYHsiZzgFaD07kf1b2PXQCgrYp7
 0uxV6shkAMNiqC1CyvIPTRA=
 =TFRT
 -----END PGP SIGNATURE-----
 
 --SLDf9lqlvOQaIe6s--

State-Changed-From-To: feedback->analyzed 
State-Changed-By: rafan 
State-Changed-When: Sun Apr 29 10:24:31 UTC 2007 
State-Changed-Why:  
This problem is fixed in latest ncurses snapshot. Tested with 
devel/ncurses-devel (5.6.20070414). There is no memory leak. 

This will be fixed in FreeBSD base when I import new ncurses 
(probably 5.7). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=98975 
State-Changed-From-To: analyzed->patched 
State-Changed-By: rafan 
State-Changed-When: Wed Jan 2 15:26:06 UTC 2008 
State-Changed-Why:  
5.6 snapshot  20071222 is imported in 8.x. This should 
fix this problem. Will MFC once 5.7 release is imported. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=98975 
State-Changed-From-To: patched->closed 
State-Changed-By: rafan 
State-Changed-When: Tue Jul 1 09:29:22 UTC 2008 
State-Changed-Why:  
ncurses 5.6 snapshot 20080503 is committed in HEAD, 7 and6. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=98975 
>Unformatted:
