]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/db_iterator.c
ncurses 6.4 - patch 20240420
[ncurses.git] / ncurses / tinfo / db_iterator.c
index a9d4e7bbfed0fe646e3d16b068a5c3717e29c0cc..db3872e3f90d3e932ddd54bc35f5802026269f1a 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2006-2017,2018 Free Software Foundation, Inc.              *
+ * Copyright 2018-2022,2023 Thomas E. Dickey                                *
+ * Copyright 2006-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            *
@@ -43,7 +44,7 @@
 #include <hashed_db.h>
 #endif
 
-MODULE_ID("$Id: db_iterator.c,v 1.47 2018/11/24 22:42:01 tom Exp $")
+MODULE_ID("$Id: db_iterator.c,v 1.50 2023/06/24 21:52:32 tom Exp $")
 
 #define HaveTicDirectory _nc_globals.have_tic_directory
 #define KeepTicDirectory _nc_globals.keep_tic_directory
@@ -201,6 +202,13 @@ free_cache(void)
     FreeAndNull(my_list);
 }
 
+static void
+update_tic_dir(const char *update)
+{
+    free((char *) TicDirectory);
+    TicDirectory = update;
+}
+
 /*
  * Record the "official" location of the terminfo directory, according to
  * the place where we're writing to, or the normal default, if not.
@@ -210,8 +218,9 @@ _nc_tic_dir(const char *path)
 {
     T(("_nc_tic_dir %s", NonNull(path)));
     if (!KeepTicDirectory) {
-       if (path != 0) {
-           TicDirectory = path;
+       if (path != NULL) {
+           if (path != TicDirectory)
+               update_tic_dir(strdup(path));
            HaveTicDirectory = TRUE;
        } else if (HaveTicDirectory == 0) {
            if (use_terminfo_vars()) {
@@ -374,8 +383,11 @@ _nc_first_db(DBDIRS * state, int *offset)
                 */
                for (j = 0; my_list[j] != 0; ++j) {
 #ifdef TERMINFO
-                   if (*my_list[j] == '\0')
-                       my_list[j] = strdup(TERMINFO);
+                   if (*my_list[j] == '\0') {
+                       char *my_copy = strdup(TERMINFO);
+                       if (my_copy != 0)
+                           my_list[j] = my_copy;
+                   }
 #endif
                    trim_formatting(my_list[j]);
                    for (k = 0; k < j; ++k) {
@@ -443,5 +455,6 @@ _nc_db_iterator_leaks(void)
        FreeIfNeeded(my_vars[which].value);
        my_vars[which].value = 0;
     }
+    update_tic_dir(NULL);
 }
 #endif