lib_freeall.c revision 262629
150276Speter/**************************************************************************** 2262629Sdelphij * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc. * 350276Speter * * 450276Speter * Permission is hereby granted, free of charge, to any person obtaining a * 550276Speter * copy of this software and associated documentation files (the * 650276Speter * "Software"), to deal in the Software without restriction, including * 750276Speter * without limitation the rights to use, copy, modify, merge, publish, * 850276Speter * distribute, distribute with modifications, sublicense, and/or sell * 950276Speter * copies of the Software, and to permit persons to whom the Software is * 1050276Speter * furnished to do so, subject to the following conditions: * 1150276Speter * * 1250276Speter * The above copyright notice and this permission notice shall be included * 1350276Speter * in all copies or substantial portions of the Software. * 1450276Speter * * 1550276Speter * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 1650276Speter * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 1750276Speter * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 1850276Speter * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 1950276Speter * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 2050276Speter * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 2150276Speter * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 2250276Speter * * 2350276Speter * Except as contained in this notice, the name(s) of the above copyright * 2450276Speter * holders shall not be used in advertising or otherwise to promote the * 2550276Speter * sale, use or other dealings in this Software without prior written * 2650276Speter * authorization. * 2750276Speter ****************************************************************************/ 2850276Speter 2950276Speter/**************************************************************************** 30174993Srafan * Author: Thomas E. Dickey 1996-on * 3150276Speter ****************************************************************************/ 3250276Speter 3350276Speter#include <curses.priv.h> 34166124Srafan#include <tic.h> 3550276Speter 3650276Speter#if HAVE_NC_FREEALL 3750276Speter 3850276Speter#if HAVE_LIBDBMALLOC 3950276Speterextern int malloc_errfd; /* FIXME */ 4050276Speter#endif 4150276Speter 42262629SdelphijMODULE_ID("$Id: lib_freeall.c,v 1.59 2010/01/23 17:57:43 tom Exp $") 4350276Speter 4450276Speter/* 4550276Speter * Free all ncurses data. This is used for testing only (there's no practical 4650276Speter * use for it as an extension). 4750276Speter */ 4876726SpeterNCURSES_EXPORT(void) 49262629SdelphijNCURSES_SP_NAME(_nc_freeall) (NCURSES_SP_DCL0) 5050276Speter{ 5162449Speter WINDOWLIST *p, *q; 52166124Srafan static va_list empty_va; 5350276Speter 54166124Srafan T((T_CALLED("_nc_freeall()"))); 5550276Speter#if NO_LEAKS 56262629Sdelphij if (SP_PARM != 0) { 57262629Sdelphij if (SP_PARM->_oldnum_list != 0) { 58262629Sdelphij FreeAndNull(SP_PARM->_oldnum_list); 59174993Srafan } 60262629Sdelphij if (SP_PARM->_panelHook.destroy != 0) { 61262629Sdelphij SP_PARM->_panelHook.destroy(SP_PARM->_panelHook.stdscr_pseudo_panel); 62184989Srafan } 63166124Srafan } 6450276Speter#endif 65262629Sdelphij if (SP_PARM != 0) { 66184989Srafan _nc_lock_global(curses); 67174993Srafan 68262629Sdelphij while (WindowList(SP_PARM) != 0) { 69174993Srafan bool deleted = FALSE; 70174993Srafan 7162449Speter /* Delete only windows that're not a parent */ 72262629Sdelphij for (each_window(SP_PARM, p)) { 7362449Speter bool found = FALSE; 7450276Speter 75262629Sdelphij for (each_window(SP_PARM, q)) { 7662449Speter if ((p != q) 7797049Speter && (q->win._flags & _SUBWIN) 7897049Speter && (&(p->win) == q->win._parent)) { 7962449Speter found = TRUE; 8062449Speter break; 8162449Speter } 8262449Speter } 8350276Speter 8462449Speter if (!found) { 85174993Srafan if (delwin(&(p->win)) != ERR) 86174993Srafan deleted = TRUE; 8762449Speter break; 8850276Speter } 8962449Speter } 90174993Srafan 91174993Srafan /* 92174993Srafan * Don't continue to loop if the list is trashed. 93174993Srafan */ 94174993Srafan if (!deleted) 95174993Srafan break; 9650276Speter } 97262629Sdelphij delscreen(SP_PARM); 98184989Srafan _nc_unlock_global(curses); 99166124Srafan } 100174993Srafan 101166124Srafan (void) _nc_printf_string(0, empty_va); 10250276Speter#ifdef TRACE 10362449Speter (void) _nc_trace_buf(-1, 0); 10450276Speter#endif 105184989Srafan#if USE_WIDEC_SUPPORT 106184989Srafan FreeIfNeeded(_nc_wacs); 107174993Srafan#endif 108174993Srafan _nc_leaks_tinfo(); 109174993Srafan 11050276Speter#if HAVE_LIBDBMALLOC 11162449Speter malloc_dump(malloc_errfd); 11250276Speter#elif HAVE_LIBDMALLOC 113166124Srafan#elif HAVE_LIBMPATROL 114166124Srafan __mp_summary(); 11550276Speter#elif HAVE_PURIFY 11662449Speter purify_all_inuse(); 11750276Speter#endif 118166124Srafan returnVoid; 11950276Speter} 12050276Speter 121262629Sdelphij#if NCURSES_SP_FUNCS 12276726SpeterNCURSES_EXPORT(void) 123262629Sdelphij_nc_freeall(void) 12450276Speter{ 125262629Sdelphij NCURSES_SP_NAME(_nc_freeall) (CURRENT_SCREEN); 126262629Sdelphij} 127262629Sdelphij#endif 128166124Srafan 129262629SdelphijNCURSES_EXPORT(void) 130262629SdelphijNCURSES_SP_NAME(_nc_free_and_exit) (NCURSES_SP_DCLx int code) 131262629Sdelphij{ 132262629Sdelphij char *last_setbuf = (SP_PARM != 0) ? SP_PARM->_setbuf : 0; 133262629Sdelphij 134262629Sdelphij NCURSES_SP_NAME(_nc_freeall) (NCURSES_SP_ARG); 135166124Srafan#ifdef TRACE 136166124Srafan trace(0); /* close trace file, freeing its setbuf */ 137184989Srafan { 138184989Srafan static va_list fake; 139184989Srafan free(_nc_varargs("?", fake)); 140184989Srafan } 141166124Srafan#endif 142166124Srafan fclose(stdout); 143166124Srafan FreeIfNeeded(last_setbuf); 14462449Speter exit(code); 14550276Speter} 14662449Speter 14750276Speter#else 14876726SpeterNCURSES_EXPORT(void) 14962449Speter_nc_freeall(void) 15062449Speter{ 15162449Speter} 152184989Srafan 153184989SrafanNCURSES_EXPORT(void) 154262629SdelphijNCURSES_SP_NAME(_nc_free_and_exit) (NCURSES_SP_DCLx int code) 155184989Srafan{ 156262629Sdelphij if (SP_PARM) { 157262629Sdelphij delscreen(SP_PARM); 158262629Sdelphij if (SP_PARM->_term) 159262629Sdelphij NCURSES_SP_NAME(del_curterm) (NCURSES_SP_ARGx SP_PARM->_term); 160262629Sdelphij } 161184989Srafan exit(code); 162184989Srafan} 16350276Speter#endif 164262629Sdelphij 165262629Sdelphij#if NCURSES_SP_FUNCS 166262629SdelphijNCURSES_EXPORT(void) 167262629Sdelphij_nc_free_and_exit(int code) 168262629Sdelphij{ 169262629Sdelphij NCURSES_SP_NAME(_nc_free_and_exit) (CURRENT_SCREEN, code); 170262629Sdelphij} 171262629Sdelphij#endif 172