Skip to content

Commit

Permalink
New 'PDC_free_memory_allocations()' frees the clipboard, SP, and plat…
Browse files Browse the repository at this point in the history
…form-specific memory allocations. Also a start to fixing issue wmcbrine/PDCurses#134,  to make endwin() signal-safe (still some work to do on that front,  though.)
  • Loading branch information
Bill-Gray committed Jul 6, 2022
1 parent fc520ca commit 8d10534
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 10 deletions.
5 changes: 3 additions & 2 deletions curses.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Defined by this header:
#define PDC_VER_MINOR 3
#define PDC_VER_CHANGE 3
#define PDC_VER_YEAR 2022
#define PDC_VER_MONTH 06
#define PDC_VER_DAY 26
#define PDC_VER_MONTH 07
#define PDC_VER_DAY 06

#define PDC_STRINGIZE( x) #x
#define PDC_stringize( x) PDC_STRINGIZE( x)
Expand Down Expand Up @@ -1761,6 +1761,7 @@ PDCEX void PDC_set_resize_limits( const int new_min_lines,
const int new_max_lines,
const int new_min_cols,
const int new_max_cols);
PDCEX void PDC_free_memory_allocations( void);

#define FUNCTION_KEY_SHUT_DOWN 0
#define FUNCTION_KEY_PASTE 1
Expand Down
2 changes: 2 additions & 0 deletions curspriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void PDC_scr_free(void);
int PDC_scr_open(void);
void PDC_set_keyboard_binary(bool);
void PDC_transform_line(int, int, int, const chtype *);
void PDC_free_platform_dependent_memory( void);
const char *PDC_sysname(void);

/* Internal cross-module functions */
Expand Down Expand Up @@ -133,4 +134,5 @@ PDCEX int PDC_wcwidth( const int32_t ucs);

#define _is_altcharset( ch) (((ch) & (A_ALTCHARSET | (A_CHARTEXT ^ 0x7f))) == A_ALTCHARSET)


#endif /* __CURSES_INTERNALS__ */
7 changes: 7 additions & 0 deletions docs/IMPLEMNT.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
PDCurses Implementor's Guide
============================

2022/07/06 - added PDC_free_platform_dependent_memory()
- Version 1.6 - 2019/09/?? - added PDC_doupdate(); removed argc, argv,
lines, cols and SP allocation from
PDC_scr_open(); removed PDC_init_pair(),
Expand Down Expand Up @@ -245,6 +246,12 @@ the cursor to the lower left corner. (The X11 port does nothing.)

Free any memory allocated by PDC_scr_open(). Called by delscreen().

### void PDC_free_platform_dependent_memory( void);

Free any platform-specific memory. Called by PDC_free_memory_allocations().
Does nothing (at present) on all platforms except DOS and OS/2. On those,
it frees the initial screen state.

### int PDC_scr_open(void);

The platform-specific part of initscr(). It must initialize acs_map[]
Expand Down
11 changes: 8 additions & 3 deletions dos/pdcscrn.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ void PDC_scr_close(void)
#endif
PDC_LOG(("PDC_scr_close() - called\n"));

if (getenv("PDC_RESTORE_SCREEN") && saved_screen)
if( saved_screen)
{
#ifdef __DJGPP__
dosmemput(saved_screen, saved_lines * saved_cols * 2,
Expand All @@ -463,8 +463,6 @@ void PDC_scr_close(void)
(void *)saved_screen, (saved_lines * saved_cols * 2));
# endif
#endif
free(saved_screen);
saved_screen = NULL;
}

reset_shell_mode();
Expand Down Expand Up @@ -704,3 +702,10 @@ void PDC_set_resize_limits( const int new_min_lines, const int new_max_lines,
INTENTIONALLY_UNUSED_PARAMETER( new_min_cols);
INTENTIONALLY_UNUSED_PARAMETER( new_max_cols);
}

void PDC_free_platform_dependent_memory( void)
{
if( saved_screen)
free(saved_screen);
saved_screen = NULL;
}
4 changes: 4 additions & 0 deletions dosvga/pdcscrn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1735,3 +1735,7 @@ void PDC_set_resize_limits( const int new_min_lines, const int new_max_lines,
const int new_min_cols, const int new_max_cols)
{
}

void PDC_free_platform_dependent_memory( void)
{
}
4 changes: 4 additions & 0 deletions fb/pdcscrn.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,7 @@ int PDC_init_color( int color, int red, int green, int blue)
}
return OK;
}

void PDC_free_platform_dependent_memory( void)
{
}
12 changes: 7 additions & 5 deletions os2/pdcscrn.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,9 @@ void PDC_scr_close(void)
PDC_LOG(("PDC_scr_close() - called\n"));

if (saved_screen && getenv("PDC_RESTORE_SCREEN"))
{
VioWrtCellStr(saved_screen, saved_lines * saved_cols * 2,
0, 0, (HVIO)NULL);

free(saved_screen);
saved_screen = NULL;
}

reset_shell_mode();

if (SP->visibility != 1)
Expand Down Expand Up @@ -231,3 +226,10 @@ void PDC_set_resize_limits( const int new_min_lines, const int new_max_lines,
const int new_min_cols, const int new_max_cols)
{
}

void PDC_free_platform_dependent_memory( void)
{
if( saved_screen)
free(saved_screen);
saved_screen = NULL;
}
17 changes: 17 additions & 0 deletions pdcurses/initscr.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ initscr
SCREEN *newterm(const char *type, FILE *outfd, FILE *infd);
SCREEN *set_term(SCREEN *new);
void delscreen(SCREEN *sp);
void PDC_free_memory_allocations( void);
int resize_term(int nlines, int ncols);
bool is_termresized(void);
Expand Down Expand Up @@ -51,6 +52,15 @@ initscr
needed. In PDCurses, the parameter must be the value of SP, and
delscreen() sets SP to NULL.
PDC_free_memory_allocations() frees all memory allocated by PDCurses,
including SP and any platform-dependent memory. It should be called
after endwin(), not instead of it. It need not be called, because
remaining memory will be freed at exit; but it can help in diagnosing
memory leak issues by ruling out any from PDCurses.
Note that SDLn and X11 have known memory leaks within their libraries,
which appear to be effectively unfixable.
set_term() does nothing meaningful in PDCurses, but is included for
compatibility with other curses implementations.
Expand Down Expand Up @@ -321,6 +331,13 @@ bool isendwin(void)
return SP ? !(SP->alive) : FALSE;
}

void PDC_free_memory_allocations( void)
{
PDC_free_platform_dependent_memory( );
PDC_clearclipboard( );
delscreen( SP);
}

SCREEN *newterm(const char *type, FILE *outfd, FILE *infd)
{
PDC_LOG(("newterm() - called\n"));
Expand Down
4 changes: 4 additions & 0 deletions plan9/pdcscrn.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,7 @@ void PDC_scr_free(void)
{
free(SP);
}

void PDC_free_platform_dependent_memory( void)
{
}
4 changes: 4 additions & 0 deletions sdl1/pdcscrn.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,7 @@ void PDC_set_resize_limits( const int new_min_lines,
INTENTIONALLY_UNUSED_PARAMETER( new_max_cols);
return;
}

void PDC_free_platform_dependent_memory( void)
{
}
4 changes: 4 additions & 0 deletions sdl2/pdcscrn.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,7 @@ void PDC_set_resize_limits( const int new_min_lines, const int new_max_lines,
INTENTIONALLY_UNUSED_PARAMETER( new_min_cols);
INTENTIONALLY_UNUSED_PARAMETER( new_max_cols);
}

void PDC_free_platform_dependent_memory( void)
{
}
4 changes: 4 additions & 0 deletions vt/pdcscrn.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,7 @@ int PDC_init_color( int color, int red, int green, int blue)
curscr->_clear = TRUE;
return OK;
}

void PDC_free_platform_dependent_memory( void)
{
}
4 changes: 4 additions & 0 deletions wincon/pdcscrn.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,7 @@ void PDC_set_resize_limits( const int new_min_lines, const int new_max_lines,
INTENTIONALLY_UNUSED_PARAMETER( new_min_cols);
INTENTIONALLY_UNUSED_PARAMETER( new_max_cols);
}

void PDC_free_platform_dependent_memory( void)
{
}
4 changes: 4 additions & 0 deletions wingui/pdcscrn.c
Original file line number Diff line number Diff line change
Expand Up @@ -2422,3 +2422,7 @@ int PDC_init_color( int color, int red, int green, int blue)
PDC_set_palette_entry( color, new_rgb);
return OK;
}

void PDC_free_platform_dependent_memory( void)
{
}
4 changes: 4 additions & 0 deletions x11/pdcscrn.c
Original file line number Diff line number Diff line change
Expand Up @@ -827,3 +827,7 @@ void PDC_set_resize_limits( const int new_min_lines, const int new_max_lines,
PDC_min_cols = max( new_min_cols, 2);
PDC_max_cols = max( new_max_cols, PDC_min_cols);
}

void PDC_free_platform_dependent_memory( void)
{
}

0 comments on commit 8d10534

Please sign in to comment.