| 1 |
.\"*************************************************************************** |
| 2 |
.\" Copyright 2019-2023,2024 Thomas E. Dickey * |
| 3 |
.\" Copyright 2008-2010,2017 Free Software Foundation, Inc. * |
| 4 |
.\" * |
| 5 |
.\" Permission is hereby granted, free of charge, to any person obtaining a * |
| 6 |
.\" copy of this software and associated documentation files (the * |
| 7 |
.\" "Software"), to deal in the Software without restriction, including * |
| 8 |
.\" without limitation the rights to use, copy, modify, merge, publish, * |
| 9 |
.\" distribute, distribute with modifications, sublicense, and/or sell * |
| 10 |
.\" copies of the Software, and to permit persons to whom the Software is * |
| 11 |
.\" furnished to do so, subject to the following conditions: * |
| 12 |
.\" * |
| 13 |
.\" The above copyright notice and this permission notice shall be included * |
| 14 |
.\" in all copies or substantial portions of the Software. * |
| 15 |
.\" * |
| 16 |
.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * |
| 17 |
.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * |
| 18 |
.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * |
| 19 |
.\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * |
| 20 |
.\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * |
| 21 |
.\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * |
| 22 |
.\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. * |
| 23 |
.\" * |
| 24 |
.\" Except as contained in this notice, the name(s) of the above copyright * |
| 25 |
.\" holders shall not be used in advertising or otherwise to promote the * |
| 26 |
.\" sale, use or other dealings in this Software without prior written * |
| 27 |
.\" authorization. * |
| 28 |
.\"*************************************************************************** |
| 29 |
.\" |
| 30 |
.\" $Id: curs_memleaks.3x,v 1.35 2024/03/16 15:35:01 tom Exp $ |
| 31 |
.TH memleaks 3NCURSES 2024-03-16 "ncurses 6.6" "Library calls" |
| 32 |
.ie \n(.g \{\ |
| 33 |
.ds `` \(lq |
| 34 |
.ds '' \(rq |
| 35 |
.\} |
| 36 |
.el \{\ |
| 37 |
.ie t .ds `` `` |
| 38 |
.el .ds `` "" |
| 39 |
.ie t .ds '' '' |
| 40 |
.el .ds '' "" |
| 41 |
.\} |
| 42 |
. |
| 43 |
.de bP |
| 44 |
.ie n .IP \(bu 4 |
| 45 |
.el .IP \(bu 2 |
| 46 |
.. |
| 47 |
.SH NAME |
| 48 |
\fB\%exit_curses\fP, |
| 49 |
\fB\%exit_terminfo\fP \- |
| 50 |
check for memory leaks in \fIcurses\fR |
| 51 |
.SH SYNOPSIS |
| 52 |
.nf |
| 53 |
\fB#include <curses.h> |
| 54 |
\fBvoid exit_curses(int \fIcode\fP); |
| 55 |
.PP |
| 56 |
\fB#include <term.h> |
| 57 |
\fBvoid exit_terminfo(int \fIcode\fP); |
| 58 |
.PP |
| 59 |
\fI/* deprecated (intentionally not declared in curses.h or term.h) */ |
| 60 |
\fBvoid _nc_freeall(void); |
| 61 |
\fBvoid _nc_free_and_exit(int \fIcode\fP); |
| 62 |
\fBvoid _nc_free_tinfo(int \fIcode\fP); |
| 63 |
.fi |
| 64 |
.SH DESCRIPTION |
| 65 |
These functions are used to simplify analysis of memory leaks in the |
| 66 |
\fI\%ncurses\fP library. |
| 67 |
.PP |
| 68 |
Any implementation of curses must not free the memory associated with |
| 69 |
a screen, since (even after calling \fB\%endwin\fP(3NCURSES)), it must be available |
| 70 |
for use in the next call to \fB\%refresh\fP(3NCURSES). |
| 71 |
There are also chunks of memory held for performance reasons. |
| 72 |
That makes it hard to analyze curses applications for memory leaks. |
| 73 |
When using the specially configured debugging version of the |
| 74 |
\fI\%ncurses\fP library, |
| 75 |
applications can call functions which free those chunks of memory, |
| 76 |
simplifying the process of memory-leak checking. |
| 77 |
.PP |
| 78 |
Some of the functions are named with a \*(``_nc_\*('' prefix |
| 79 |
because they are not intended for use in the non-debugging library: |
| 80 |
.TP 5 |
| 81 |
\fB\%_nc_freeall\fP |
| 82 |
This frees (almost) all of the memory allocated by \fI\%ncurses\fP. |
| 83 |
.TP 5 |
| 84 |
\fB\%_nc_free_and_exit\fP |
| 85 |
This frees the memory allocated by \fI\%ncurses\fP |
| 86 |
(like \fB\%_nc_freeall\fP), |
| 87 |
and exits the program. |
| 88 |
It is preferred over \fB\%_nc_freeall\fP since some of that memory |
| 89 |
may be required to keep the application running. |
| 90 |
Simply exiting (with the given exit-code) is safer. |
| 91 |
.TP 5 |
| 92 |
\fB\%_nc_free_tinfo\fP |
| 93 |
Use this function if only the low-level terminfo functions (and |
| 94 |
corresponding library) are used. |
| 95 |
Like \fB\%_nc_free_and_exit\fP, it exits the program after freeing memory. |
| 96 |
.PP |
| 97 |
The functions prefixed \*(``_nc\*('' are normally not available; |
| 98 |
they must be configured into the library |
| 99 |
at build time using the \fB\%\-\-disable-leaks\fP option. |
| 100 |
That compiles-in code that frees memory that normally would not be freed. |
| 101 |
.PP |
| 102 |
The \fB\%exit_curses\fP and \fB\%exit_terminfo\fP functions |
| 103 |
call \fB\%_nc_free_and_exit\fP and \fB\%_nc_free_tinfo\fP if |
| 104 |
the library is configured to support memory-leak checking. |
| 105 |
If the library is not configured to support memory-leak checking, |
| 106 |
they simply call \fBexit\fP. |
| 107 |
.SH RETURN VALUE |
| 108 |
These functions do not return a value. |
| 109 |
.SH PORTABILITY |
| 110 |
These functions are not part of X/Open Curses; |
| 111 |
nor do other implementations of curses provide a similar feature. |
| 112 |
.PP |
| 113 |
In any implementation of X/Open Curses, an application can free part |
| 114 |
of the memory allocated by curses: |
| 115 |
.bP |
| 116 |
The portable part of \fB\%exit_curses\fP can be freed using \fB\%delscreen\fP, |
| 117 |
passing the \fISCREEN\fP pointer returned by \fB\%newterm\fP. |
| 118 |
.IP |
| 119 |
In some implementations, there is a global variable \fBsp\fP |
| 120 |
which could be used, e.g., if the screen were only initialized |
| 121 |
using \fB\%initscr\fP. |
| 122 |
.bP |
| 123 |
The portable part of \fB\%exit_terminfo\fP can be freed |
| 124 |
using \fB\%del_curterm\fP. |
| 125 |
.IP |
| 126 |
In this case, there is a global variable \fB\%cur_term\fP which can be |
| 127 |
used as parameter. |
| 128 |
.SH SEE ALSO |
| 129 |
\fB\%ncurses\fP(3NCURSES), |
| 130 |
\fB\%initscr\fP(3NCURSES), |
| 131 |
\fB\%terminfo\fP(3NCURSES) |