- if (win->_flags & _SUBWIN)
- touchwin(win->_parent);
- else if (curscr != 0)
- touchwin(curscr);
-
- returnCode(_nc_freewin(win));
+ if (_nc_try_global(curses) == 0) {
+ if (win == 0
+ || cannot_delete(win)) {
+ result = ERR;
+ } else if (IS_PAD(win)) {
+ win->_parent = NULL;
+ result = OK;
+ } else {
+#if NCURSES_SP_FUNCS
+ SCREEN *sp = _nc_screen_of(win);
+#endif
+ if (IS_SUBWIN(win)) {
+ touchwin(win->_parent);
+ } else if (CurScreen(SP_PARM) != 0) {
+ touchwin(CurScreen(SP_PARM));
+ }
+ result = _nc_freewin(win);
+ }
+ _nc_unlock_global(curses);
+ }
+ returnCode(result);