Skip to content

Commit

Permalink
PDC_free_memory_allocations( ) wasn't totally stupid, but it shouldn'…
Browse files Browse the repository at this point in the history
…t be needed. The specifications say that delscreen( ) 'frees storage associated with the SCREEN data structure', i.e., it really ought to do everything that PDC_free_memory_allocations( ) is doing; there's no need for a PDCursesMod extension.
  • Loading branch information
Bill-Gray committed Aug 21, 2022
1 parent 60138ca commit 0223039
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 47 deletions.
1 change: 0 additions & 1 deletion curses.h
Original file line number Diff line number Diff line change
Expand Up @@ -1765,7 +1765,6 @@ 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: 1 addition & 1 deletion demos/init_col.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ int main( const int argc, const char *argv[])

endwin( );
#ifdef __PDCURSESMOD__ /* Not really needed, but ensures Valgrind */
PDC_free_memory_allocations( ); /* says all memory was freed */
delscreen( SP); /* says all memory was freed */
#endif
return( -1);
}
2 changes: 1 addition & 1 deletion demos/mbrot.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ int main( const int argc, const char **argv)

endwin( );
#ifdef __PDCURSESMOD__ /* Not really needed, but ensures Valgrind */
PDC_free_memory_allocations( ); /* says all memory was freed */
delscreen( SP); /* says all memory was freed */
#endif
return( 0);
}
2 changes: 1 addition & 1 deletion demos/newtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ int main( int argc, char **argv)

endwin();
#ifdef __PDCURSESMOD__ /* Not really needed, but ensures Valgrind */
PDC_free_memory_allocations( ); /* says all memory was freed */
delscreen( SP); /* says all memory was freed */
#endif

return 0;
Expand Down
2 changes: 1 addition & 1 deletion demos/ozdemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ int main(int argc, char **argv)
delwin(win);
endwin();
#ifdef __PDCURSESMOD__ /* Not really needed, but ensures Valgrind */
PDC_free_memory_allocations( ); /* says all memory was freed */
delscreen( SP); /* says all memory was freed */
#endif

return 0;
Expand Down
2 changes: 1 addition & 1 deletion demos/picsview.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ int main( const int argc, const char *argv[])
free( pixels);
endwin();
#ifdef __PDCURSESMOD__ /* Not really needed, but ensures Valgrind */
PDC_free_memory_allocations( ); /* says all memory was freed */
delscreen( SP); /* says all memory was freed */
#endif
return( 0);
}
2 changes: 1 addition & 1 deletion demos/test_pan.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ int main()
delwin( my_wins[i]);
}
#ifdef __PDCURSESMOD__ /* Not really needed, but ensures Valgrind */
PDC_free_memory_allocations( ); /* says all memory was freed */
delscreen( SP); /* says all memory was freed */
#endif
return( 0);
}
11 changes: 3 additions & 8 deletions demos/testcurs.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ COMMAND command[MAX_OPTIONS] =

int width, height;
static bool report_mouse_movement = FALSE;
#ifndef XCURSES
static SCREEN *screen_pointer;
#endif

int main(int argc, char *argv[])
{
Expand Down Expand Up @@ -249,12 +247,8 @@ int main(int argc, char *argv[])

delwin(win);
endwin();
#ifdef __PDCURSESMOD__ /* Not really needed, but ensures Valgrind */
PDC_free_memory_allocations( ); /* says all memory was freed */
#else
delscreen( screen_pointer);
#endif

/* Not really needed, but ensures Valgrind */
delscreen( screen_pointer); /* says all memory was freed */
return 0;
}

Expand All @@ -280,6 +274,7 @@ int initTest(WINDOW **win, int argc, char *argv[])
{
#ifdef XCURSES
Xinitscr(argc, argv);
screen_pointer = SP;
#else
INTENTIONALLY_UNUSED_PARAMETER( argv);
INTENTIONALLY_UNUSED_PARAMETER( argc);
Expand Down
2 changes: 1 addition & 1 deletion demos/widetest.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int main( const int argc, const char *argv[])
resize_term( 0, 0);
endwin( );
#ifdef __PDCURSESMOD__ /* Not really needed, but ensures Valgrind */
PDC_free_memory_allocations( ); /* says all memory was freed */
delscreen( SP); /* says all memory was freed */
#endif
return( -1);
}
Expand Down
2 changes: 1 addition & 1 deletion demos/worm.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static void cleanup(void)
curs_set(1);
endwin();
#ifdef __PDCURSESMOD__ /* Not really needed, but ensures Valgrind */
PDC_free_memory_allocations( ); /* says all memory was freed */
delscreen( SP); /* says all memory was freed */
#endif
}

Expand Down
15 changes: 2 additions & 13 deletions docs/MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,6 @@ 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 @@ -1390,15 +1389,6 @@ 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 @@ -2948,9 +2938,8 @@ window
ncols to COLS - begx. Create a new full-screen window by calling
newwin(0, 0, 0, 0).

delwin() deletes the named window, freeing all associated memory. In
the case of overlapping windows, subwindows should be deleted before
the main window.
delwin() deletes the named window, freeing all associated memory.
Subwindows must be deleted before the main window can be deleted.

mvwin() moves the window so that the upper left-hand corner is at
position (y,x). If the move would cause the window to be off the
Expand Down
18 changes: 1 addition & 17 deletions pdcurses/initscr.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ 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 @@ -52,15 +51,6 @@ 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 @@ -334,13 +324,6 @@ bool isendwin(void)
return SP ? !(SP->alive) : FALSE;
}

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

SCREEN *newterm(const char *type, FILE *outfd, FILE *infd)
{
PDC_LOG(("newterm() - called\n"));
Expand Down Expand Up @@ -370,6 +353,7 @@ void delscreen(SCREEN *sp)
if (!SP || sp != SP)
return;

traceoff( );
free(SP->c_ungch);
free(SP->c_buffer);

Expand Down

0 comments on commit 0223039

Please sign in to comment.