]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/lib_tparm.c
ncurses 6.2 - patch 20210320
[ncurses.git] / ncurses / tinfo / lib_tparm.c
index 7f0b20b99f6720a13c6a4dbe337fe1708c0f2d09..f41d4201fdefc97e58037153f98aaef2b1bca365 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright 2018-2019,2020 Thomas E. Dickey                                *
+ * Copyright 2018-2020,2021 Thomas E. Dickey                                *
  * Copyright 1998-2016,2017 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -53,7 +53,7 @@
 #include <ctype.h>
 #include <tic.h>
 
-MODULE_ID("$Id: lib_tparm.c,v 1.128 2020/10/10 21:18:09 tom Exp $")
+MODULE_ID("$Id: lib_tparm.c,v 1.130 2021/03/20 12:36:34 tom Exp $")
 
 /*
  *     char *
@@ -173,14 +173,16 @@ _nc_free_tparm(void)
 {
 #if HAVE_TSEARCH
     if (MyCount != 0) {
-       delete_tparm = typeMalloc(TPARM_DATA *, MyCount);
+       delete_tparm = typeCalloc(TPARM_DATA *, MyCount);
        which_tparm = 0;
        twalk(MyCache, visit_nodes);
        for (which_tparm = 0; which_tparm < MyCount; ++which_tparm) {
            TPARM_DATA *ptr = delete_tparm[which_tparm];
-           tdelete(ptr, &MyCache, cmp_format);
-           free((char *) ptr->format);
-           free(ptr);
+           if (ptr != NULL) {
+               tdelete(ptr, &MyCache, cmp_format);
+               free((char *) ptr->format);
+               free(ptr);
+           }
        }
        which_tparm = 0;
        twalk(MyCache, visit_nodes);
@@ -405,7 +407,7 @@ parse_format(const char *s, char *format, int *len)
  * may be cases that we cannot see the explicit parameter numbers.
  */
 NCURSES_EXPORT(int)
-_nc_tparm_analyze(const char *string, char *p_is_s[NUM_PARM], int *popcount)
+_nc_tparm_analyze(const char *string, char **p_is_s, int *popcount)
 {
     size_t len2;
     int i;
@@ -589,12 +591,14 @@ tparm_setup(const char *string, TPARM_DATA * result)
                if ((fs = typeCalloc(TPARM_DATA, 1)) != 0) {
                    *fs = *result;
                    if ((fs->format = strdup(string)) != 0) {
-                       if ((ft = tsearch(fs, &MyCache, cmp_format)) != 0) {
+                       if (tsearch(fs, &MyCache, cmp_format) != 0) {
                            ++MyCount;
                        } else {
+                           free(fs);
                            rc = ERR;
                        }
                    } else {
+                       free(fs);
                        rc = ERR;
                    }
                } else {