X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Fbase%2Flib_freeall.c;h=d2d5870eeed3aaf498aa22481eba1a66a09317df;hp=a5be4a589a8b1222943b7c8533f7711f94e858fb;hb=8890c8f28a1db5995ef17f52a7d8c0b9cf574210;hpb=55ccd2b959766810cf7db8d1c4462f338ce0afc8 diff --git a/ncurses/base/lib_freeall.c b/ncurses/base/lib_freeall.c index a5be4a58..d2d5870e 100644 --- a/ncurses/base/lib_freeall.c +++ b/ncurses/base/lib_freeall.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc. * + * Copyright (c) 1998-2018,2019 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -27,11 +27,10 @@ ****************************************************************************/ /**************************************************************************** - * Author: Thomas E. Dickey 1996,1997 * + * Author: Thomas E. Dickey 1996-on * ****************************************************************************/ #include -#include #include #if HAVE_NC_FREEALL @@ -40,69 +39,90 @@ extern int malloc_errfd; /* FIXME */ #endif -MODULE_ID("$Id: lib_freeall.c,v 1.33 2005/06/04 22:34:01 tom Exp $") +MODULE_ID("$Id: lib_freeall.c,v 1.70 2019/12/07 20:28:03 tom Exp $") /* * Free all ncurses data. This is used for testing only (there's no practical * use for it as an extension). */ NCURSES_EXPORT(void) -_nc_freeall(void) +NCURSES_SP_NAME(_nc_freeall) (NCURSES_SP_DCL0) { - WINDOWLIST *p, *q; - char *s; + static va_list empty_va; T((T_CALLED("_nc_freeall()"))); #if NO_LEAKS - _nc_free_tparm(); - if (_nc_oldnums != 0) { - FreeAndNull(_nc_oldnums); + _nc_globals.leak_checking = TRUE; + if (SP_PARM != 0) { + if (SP_PARM->_oldnum_list != 0) { + FreeAndNull(SP_PARM->_oldnum_list); + } + if (SP_PARM->_panelHook.destroy != 0) { + SP_PARM->_panelHook.destroy(SP_PARM->_panelHook.stdscr_pseudo_panel); + } +#if NCURSES_EXT_COLORS + _nc_new_pair_leaks(SP_PARM); +#endif } #endif - if (SP != 0) { - while (_nc_windows != 0) { + if (SP_PARM != 0) { + _nc_lock_global(curses); + + while (WindowList(SP_PARM) != 0) { + WINDOWLIST *p, *q; + bool deleted = FALSE; + /* Delete only windows that're not a parent */ - for (p = _nc_windows; p != 0; p = p->next) { + for (each_window(SP_PARM, p)) { + WINDOW *p_win = &(p->win); bool found = FALSE; - for (q = _nc_windows; q != 0; q = q->next) { +#ifndef USE_SP_WINDOWLIST + if (p->screen != SP_PARM) + continue; +#endif + + for (each_window(SP_PARM, q)) { + WINDOW *q_win = &(q->win); + +#ifndef USE_SP_WINDOWLIST + if (q->screen != SP_PARM) + continue; +#endif + if ((p != q) - && (q->win._flags & _SUBWIN) - && (&(p->win) == q->win._parent)) { + && (q_win->_flags & _SUBWIN) + && (p_win == q_win->_parent)) { found = TRUE; break; } } if (!found) { - delwin(&(p->win)); + if (delwin(p_win) != ERR) + deleted = TRUE; break; } } + + /* + * Don't continue to loop if the list is trashed. + */ + if (!deleted) + break; } - delscreen(SP); + delscreen(SP_PARM); + _nc_unlock_global(curses); } - del_curterm(cur_term); - _nc_free_entries(_nc_head); - _nc_get_type(0); - _nc_first_name(0); + (void) _nc_printf_string(0, empty_va); +#ifdef TRACE + (void) _nc_trace_buf(-1, (size_t) 0); +#endif #if USE_WIDEC_SUPPORT FreeIfNeeded(_nc_wacs); #endif -#if NO_LEAKS - _nc_alloc_entry_leaks(); - _nc_captoinfo_leaks(); - _nc_comp_scan_leaks(); -#endif - - if ((s = _nc_home_terminfo()) != 0) - free(s); - - (void) _nc_printf_string(0, 0); -#ifdef TRACE - (void) _nc_trace_buf(-1, 0); -#endif + _nc_leaks_tinfo(); #if HAVE_LIBDBMALLOC malloc_dump(malloc_errfd); @@ -115,18 +135,27 @@ _nc_freeall(void) returnVoid; } +#if NCURSES_SP_FUNCS NCURSES_EXPORT(void) -_nc_free_and_exit(int code) +_nc_freeall(void) { - char *last_setbuf = (SP != 0) ? SP->_setbuf : 0; + NCURSES_SP_NAME(_nc_freeall) (CURRENT_SCREEN); +} +#endif - _nc_freeall(); +NCURSES_EXPORT(void) +NCURSES_SP_NAME(_nc_free_and_exit) (NCURSES_SP_DCLx int code) +{ + T((T_CALLED("_nc_free_and_exit(%d)"), code)); + NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG); + NCURSES_SP_NAME(_nc_freeall) (NCURSES_SP_ARG); #ifdef TRACE - trace(0); /* close trace file, freeing its setbuf */ - free(_nc_varargs("?", 0)); + curses_trace(0); /* close trace file, freeing its setbuf */ + { + static va_list fake; + free(_nc_varargs("?", fake)); + } #endif - fclose(stdout); - FreeIfNeeded(last_setbuf); exit(code); } @@ -135,4 +164,23 @@ NCURSES_EXPORT(void) _nc_freeall(void) { } + +NCURSES_EXPORT(void) +NCURSES_SP_NAME(_nc_free_and_exit) (NCURSES_SP_DCLx int code) +{ + if (SP_PARM) { + delscreen(SP_PARM); + if (SP_PARM->_term) + NCURSES_SP_NAME(del_curterm) (NCURSES_SP_ARGx SP_PARM->_term); + } + exit(code); +} +#endif + +#if NCURSES_SP_FUNCS +NCURSES_EXPORT(void) +_nc_free_and_exit(int code) +{ + NCURSES_SP_NAME(_nc_free_and_exit) (CURRENT_SCREEN, code); +} #endif