lib_freeall.c revision 50276
1228060Sbapt/**************************************************************************** 2228060Sbapt * Copyright (c) 1998 Free Software Foundation, Inc. * 3228060Sbapt * * 4228060Sbapt * Permission is hereby granted, free of charge, to any person obtaining a * 5228060Sbapt * copy of this software and associated documentation files (the * 6228060Sbapt * "Software"), to deal in the Software without restriction, including * 7228060Sbapt * without limitation the rights to use, copy, modify, merge, publish, * 8228060Sbapt * distribute, distribute with modifications, sublicense, and/or sell * 9228060Sbapt * copies of the Software, and to permit persons to whom the Software is * 10228060Sbapt * furnished to do so, subject to the following conditions: * 11228060Sbapt * * 12228060Sbapt * The above copyright notice and this permission notice shall be included * 13228060Sbapt * in all copies or substantial portions of the Software. * 14228060Sbapt * * 15228060Sbapt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 16228060Sbapt * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 17228060Sbapt * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 18228060Sbapt * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 19228060Sbapt * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 20228060Sbapt * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 21228060Sbapt * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 22228060Sbapt * * 23228060Sbapt * Except as contained in this notice, the name(s) of the above copyright * 24228060Sbapt * holders shall not be used in advertising or otherwise to promote the * 25228060Sbapt * sale, use or other dealings in this Software without prior written * 26228060Sbapt * authorization. * 27228060Sbapt ****************************************************************************/ 28228060Sbapt 29228060Sbapt/**************************************************************************** 30228060Sbapt * Author: Thomas E. Dickey <dickey@clark.net> 1996,1997 * 31228060Sbapt ****************************************************************************/ 32228060Sbapt 33228060Sbapt#include <curses.priv.h> 34228060Sbapt#include <term_entry.h> 35228060Sbapt 36228060Sbapt#if HAVE_NC_FREEALL 37228060Sbapt 38228060Sbapt#if HAVE_LIBDBMALLOC 39228060Sbaptextern int malloc_errfd; /* FIXME */ 40228060Sbapt#endif 41228060Sbapt 42228060SbaptMODULE_ID("$Id: lib_freeall.c,v 1.14 1999/04/03 23:17:06 tom Exp $") 43228060Sbapt 44228060Sbaptstatic void free_slk(SLK *p) 45228060Sbapt{ 46228060Sbapt if (p != 0) { 47228060Sbapt FreeIfNeeded(p->ent); 48228060Sbapt FreeIfNeeded(p->buffer); 49228060Sbapt free(p); 50228060Sbapt } 51228060Sbapt} 52228060Sbapt 53228060Sbaptstatic void free_tries(struct tries *p) 54228060Sbapt{ 55228060Sbapt struct tries *q; 56228060Sbapt 57228060Sbapt while (p != 0) { 58228060Sbapt q = p->sibling; 59228060Sbapt if (p->child != 0) 60228060Sbapt free_tries(p->child); 61228060Sbapt free(p); 62228060Sbapt p = q; 63228060Sbapt } 64228060Sbapt} 65228060Sbapt 66228060Sbapt/* 67228060Sbapt * Free all ncurses data. This is used for testing only (there's no practical 68228060Sbapt * use for it as an extension). 69228060Sbapt */ 70228060Sbaptvoid _nc_freeall(void) 71228060Sbapt{ 72228060Sbapt WINDOWLIST *p, *q; 73228060Sbapt 74228060Sbapt#if NO_LEAKS 75228060Sbapt _nc_free_tparm(); 76228060Sbapt#endif 77228060Sbapt while (_nc_windows != 0) { 78228060Sbapt /* Delete only windows that're not a parent */ 79228060Sbapt for (p = _nc_windows; p != 0; p = p->next) { 80228060Sbapt bool found = FALSE; 81228060Sbapt 82228060Sbapt for (q = _nc_windows; q != 0; q = q->next) { 83228060Sbapt if ((p != q) 84228060Sbapt && (q->win->_flags & _SUBWIN) 85228060Sbapt && (p->win == q->win->_parent)) { 86228060Sbapt found = TRUE; 87228060Sbapt break; 88228060Sbapt } 89228060Sbapt } 90228060Sbapt 91228060Sbapt if (!found) { 92228060Sbapt delwin(p->win); 93228060Sbapt break; 94228060Sbapt } 95228060Sbapt } 96228060Sbapt } 97228060Sbapt 98228060Sbapt if (SP != 0) { 99228060Sbapt free_tries (SP->_keytry); 100228060Sbapt free_tries (SP->_key_ok); 101228060Sbapt free_slk(SP->_slk); 102228060Sbapt FreeIfNeeded(SP->_color_pairs); 103228060Sbapt FreeIfNeeded(SP->_color_table); 104228060Sbapt /* it won't free buffer anyway */ 105228060Sbapt/* _nc_set_buffer(SP->_ofp, FALSE);*/ 106228060Sbapt#if !BROKEN_LINKER 107228060Sbapt FreeAndNull(SP); 108228060Sbapt#endif 109228060Sbapt } 110228060Sbapt 111228060Sbapt if (cur_term != 0) { 112228060Sbapt _nc_free_termtype(&(cur_term->type)); 113228060Sbapt free(cur_term); 114228060Sbapt } 115228060Sbapt 116228060Sbapt#ifdef TRACE 117228060Sbapt (void) _nc_trace_buf(-1, 0); 118228060Sbapt#endif 119228060Sbapt#if HAVE_LIBDBMALLOC 120228060Sbapt malloc_dump(malloc_errfd); 121228060Sbapt#elif HAVE_LIBDMALLOC 122228060Sbapt#elif HAVE_PURIFY 123228060Sbapt purify_all_inuse(); 124228060Sbapt#endif 125228060Sbapt} 126228060Sbapt 127228060Sbaptvoid _nc_free_and_exit(int code) 128228060Sbapt{ 129228060Sbapt _nc_freeall(); 130228060Sbapt exit(code); 131228060Sbapt} 132228060Sbapt#else 133228060Sbaptvoid _nc_freeall(void) { } 134228060Sbapt#endif 135228060Sbapt