curs_memleaks(3X)

πŸ’– curs_memleaks β€” Library calls πŸ’–

okay bestie, so this whole page is about curs_memleaks(3X) from the ncurses library-calls corner of the world, and it's literally the manual for hunting down memory leaks in curses. yes. we're doing detective work. πŸ”βœ¨


✨ NAME ✨

exit_curses, exit_terminfo β€” check for memory leaks in curses πŸ§šπŸ’œ


🌸 SYNOPSIS 🌸

#include <curses.h>
void exit_curses(int code);

#include <term.h>
void exit_terminfo(int code);

/* deprecated (intentionally not declared in curses.h or term.h) */
void _nc_freeall(void);
void _nc_free_and_exit(int code);
void _nc_free_tinfo(int code);

πŸ’… DESCRIPTION πŸ’…

so these functions exist to make memory-leak analysis in the ncurses library so much easier. that's the whole job. no cap.

here's the tea: any implementation of curses must not free the memory that's tied to a screen. why? because even after you call endwin(3X), that memory still has to be sitting there ready for the next call to refresh(3X). and on top of that, there are also chunks of memory that get held onto for performance reasons. which means analyzing curses applications for memory leaks is, like, genuinely hard. 😭

but!! when you're using the specially configured debugging version of the ncurses library, your application can call functions that free those chunks of memory, which simplifies the whole memory-leak-checking process. iconic behavior tbh.

some of these functions have a _nc_ prefix because they are not meant for use in the non-debugging library:

  • _nc_freeall β€” this frees (almost) all of the memory allocated by ncurses. πŸ’€ (almost!! read that word!!)
  • _nc_free_and_exit β€” this frees the memory allocated by ncurses (like _nc_freeall does), and exits the program. it's preferred over _nc_freeall because some of that memory may actually be required to keep the application running. simply exiting (with the given exit-code) is safer. πŸ‘‘
  • _nc_free_tinfo β€” use this one if only the low-level terminfo functions (and the corresponding library) are used. like _nc_free_and_exit, it exits the program after freeing memory. πŸ¦‹

now, the functions prefixed with _nc are normally not available. they have to be configured into the library at build time using the --disable-leaks option. that option compiles-in code that frees memory that normally would not be freed. periodt.

and finally, the exit_curses and exit_terminfo functions call _nc_free_and_exit and _nc_free_tinfo if the library is configured to support memory-leak checking. if the library is not configured to support memory-leak checking, they simply call exit. that's it. that's the whole vibe check. ✨


πŸŽ€ RETURN VALUE πŸŽ€

these functions do not return a value. nothing. nada. they're void girlies. πŸ’…


🌈 PORTABILITY 🌈

heads up bestie β€” these functions are not part of X/Open Curses, and no other implementations of curses provide a similar feature. iykyk. πŸ™ˆ

in any implementation of X/Open Curses, though, an application can free part of the memory allocated by curses:

  • the portable part of exit_curses can be freed using delscreen, passing the SCREEN pointer returned by newterm.
    • in some implementations, there is a global variable sp which could be used, e.g., if the screen were only initialized using initscr.
  • the portable part of exit_terminfo can be freed using del_curterm.
    • in this case, there is a global variable cur_term which can be used as parameter.

⭐ SEE ALSO ⭐

curses(3X), curs_initscr(3X), curs_terminfo(3X) πŸ’–


okay that's the whole page, you ate that 🫢 this was ncurses version 6.6, dated 2024-03-16, and it's the curs_memleaks(3X) page signing off. go free your memory and slay πŸ’…βœ¨πŸŒˆ

πŸ“¦ where this page comes from