bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Suspected memory leak in ncurses 5.3


From: Thomas Dickey
Subject: Re: Suspected memory leak in ncurses 5.3
Date: Sat, 20 Dec 2003 19:49:58 -0500 (EST)

On Sun, 21 Dec 2003, Reuben Thomas wrote:

> I'm using ncurses 5.3 as supplied with Fedora Core 1/x86 (RPM version
> 5.3-9).
>
> The following program (foo.c):
>
> #include <ncurses.h>
>
> int main(void)
> {
>       SCREEN *s = newterm(NULL, stdout, stdin);
>       set_term(s);
>
>       endwin();
>       delscreen(s);
>
>       return 0;
> }
>
> causes a memory leak. Tell me now if I'm just doing something stupid, but
> I can't see any other "free" routine I should be running other than endwin
> and delscreen. Here is the trace produced by:

That looks about right.  The 2800 bytes is a one-time allocation that
can't be freed (see NCURSES_NO_SETBUF in the manpage).  There are several
other one-time allocations that aren't normally freed - working buffers
that would be shared by any caller, e.g., to tparm().  Some are allocated
"once" (they may be reallocated to increase the buffer size as needed),
but are retained simply because it's faster to do it this way.

Periodically I test with the --disable-leaks option.  The ExitProgram()
macro used in progs and test takes that into account and frees all of the
memory that it knows about on exit). That at least tells me if the library
has lost track of the memory.  (There are cases where that would be a leak
anyway, but those are usually much harder to find).

I'm aware that tic and toe don't free all of their memory on exit this
way; it's been a low-priority item on my to-do list for a while.
(Accounting for the memory might find something to fix in the library, but
most of their memory allocation is once-only, and needed for most of the
duration of the program).

> All the memory in question seems to have been allocated by newterm, and I
> thought that should all have been freed by delscreen.

-- 
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net




reply via email to

[Prev in Thread] Current Thread [Next in Thread]