]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/lib_cur_term.c
ncurses 6.3 - patch 20220521
[ncurses.git] / ncurses / tinfo / lib_cur_term.c
index e5cd76bf22a5dc095553619414be8e0b27c81cbd..7d7e7f1577f9c86378178438ebc93cfad05c8fb5 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998-2016,2017 Free Software Foundation, Inc.              *
+,* Copyright 2020-2021,2022 Thomas E. Dickey                                *
+ * Copyright 1998-2016,2017 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            *
@@ -38,8 +39,9 @@
 
 #include <curses.priv.h>
 #include <termcap.h>           /* ospeed */
+#include <tic.h>               /* VALID_STRING */
 
-MODULE_ID("$Id: lib_cur_term.c,v 1.41 2017/06/17 22:21:35 tom Exp $")
+MODULE_ID("$Id: lib_cur_term.c,v 1.48 2022/05/21 22:58:20 tom Exp $")
 
 #undef CUR
 #define CUR TerminalType(termp).
@@ -98,13 +100,13 @@ NCURSES_SP_NAME(set_curterm) (NCURSES_SP_DCLx TERMINAL *termp)
        if (TCB->drv &&
            TCB->drv->isTerminfo &&
            TerminalType(termp).Strings) {
-           PC = (char) ((pad_char != NULL) ? pad_char[0] : 0);
+           PC = (char) (VALID_STRING(pad_char) ? pad_char[0] : 0);
        }
        TCB->csp = SP_PARM;
 #else
        ospeed = (NCURSES_OSPEED) _nc_ospeed(termp->_baudrate);
        if (TerminalType(termp).Strings) {
-           PC = (char) ((pad_char != NULL) ? pad_char[0] : 0);
+           PC = (char) (VALID_STRING(pad_char) ? pad_char[0] : 0);
        }
 #endif
 #if !USE_REENTRANT
@@ -145,7 +147,11 @@ NCURSES_SP_NAME(del_curterm) (NCURSES_SP_DCLx TERMINAL *termp)
        );
 
 #if NCURSES_EXT_NUMBERS
+#if NCURSES_EXT_COLORS
        _nc_free_termtype(&termp->type);
+#else
+       _nc_free_termtype2(&termp->type);
+#endif
 #endif
        _nc_free_termtype2(&TerminalType(termp));
        if (termp == cur)
@@ -165,10 +171,17 @@ NCURSES_SP_NAME(del_curterm) (NCURSES_SP_DCLx TERMINAL *termp)
        /* discard memory used in tgetent's cache for this terminal */
        _nc_tgetent_leak(termp);
 #endif
+       if (--_nc_globals.terminal_count == 0) {
+           _nc_free_tparm(termp);
+       }
+
+       free(termp->tparm_state.fmt_buff);
+       free(termp->tparm_state.out_buff);
        free(termp);
 
        rc = OK;
     }
+
     returnCode(rc);
 }