X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fdb_iterator.c;h=b4f5f1239ea665b1b0a49b99575d1e9f4f364627;hp=8af267bcb8559fb504b0be2f62692744b58f4dd6;hb=7087871f804c061d339994964269f3c20e88f547;hpb=8b06e371ed1bce3dd6f37138e6becb5e1a562fe0 diff --git a/ncurses/tinfo/db_iterator.c b/ncurses/tinfo/db_iterator.c index 8af267bc..b4f5f123 100644 --- a/ncurses/tinfo/db_iterator.c +++ b/ncurses/tinfo/db_iterator.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2006-2011,2012 Free Software Foundation, Inc. * + * Copyright (c) 2006-2012,2013 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 +43,7 @@ #include #endif -MODULE_ID("$Id: db_iterator.c,v 1.31 2012/02/22 22:40:24 tom Exp $") +MODULE_ID("$Id: db_iterator.c,v 1.36 2013/05/25 20:20:08 tom Exp $") #define HaveTicDirectory _nc_globals.have_tic_directory #define KeepTicDirectory _nc_globals.keep_tic_directory @@ -96,10 +96,13 @@ static bool update_getenv(const char *name, DBDIRS which) { bool result = FALSE; - char *value = getenv(name); if (which < dbdLAST) { - if (my_vars[which].name == 0 || strcmp(my_vars[which].name, name)) { + char *value; + + if ((value = getenv(name)) == 0 || (value = strdup(value)) == 0) { + ; + } else if (my_vars[which].name == 0 || strcmp(my_vars[which].name, name)) { FreeIfNeeded(my_vars[which].value); my_vars[which].name = name; my_vars[which].value = value; @@ -112,6 +115,8 @@ update_getenv(const char *name, DBDIRS which) FreeIfNeeded(my_vars[which].value); my_vars[which].value = value; result = TRUE; + } else { + free(value); } } return result; @@ -240,6 +245,7 @@ _nc_next_db(DBDIRS * state, int *offset) NCURSES_EXPORT(void) _nc_first_db(DBDIRS * state, int *offset) { + bool cache_has_expired = FALSE; *state = dbdTIC; *offset = 0; @@ -248,12 +254,15 @@ _nc_first_db(DBDIRS * state, int *offset) /* build a blob containing all of the strings we will use for a lookup * table. */ - if (my_blob == 0) { + if (my_blob == 0 || (cache_has_expired = cache_expired())) { size_t blobsize = 0; const char *values[dbdLAST]; struct stat *my_stat; int j, k; + if (cache_has_expired) + free_cache(); + for (j = 0; j < dbdLAST; ++j) values[j] = 0; @@ -263,7 +272,7 @@ _nc_first_db(DBDIRS * state, int *offset) */ values[dbdTIC] = TicDirectory; -#if USE_DATABASE +#if NCURSES_USE_DATABASE #ifdef TERMINFO_DIRS values[dbdCfgList] = TERMINFO_DIRS; #endif @@ -272,19 +281,19 @@ _nc_first_db(DBDIRS * state, int *offset) #endif #endif -#if USE_TERMCAP +#if NCURSES_USE_TERMCAP values[dbdCfgList2] = TERMPATH; #endif if (use_terminfo_vars()) { -#if USE_DATABASE +#if NCURSES_USE_DATABASE values[dbdEnvOnce] = cache_getenv("TERMINFO", dbdEnvOnce); values[dbdHome] = _nc_home_terminfo(); (void) cache_getenv("HOME", dbdHome); values[dbdEnvList] = cache_getenv("TERMINFO_DIRS", dbdEnvList); #endif -#if USE_TERMCAP +#if NCURSES_USE_TERMCAP values[dbdEnvOnce2] = cache_getenv("TERMCAP", dbdEnvOnce2); /* only use $TERMCAP if it is an absolute path */ if (values[dbdEnvOnce2] != 0 @@ -292,7 +301,7 @@ _nc_first_db(DBDIRS * state, int *offset) values[dbdEnvOnce2] = 0; } values[dbdEnvList2] = cache_getenv("TERMPATH", dbdEnvList2); -#endif /* USE_TERMCAP */ +#endif /* NCURSES_USE_TERMCAP */ } for (j = 0; j < dbdLAST; ++j) { @@ -387,9 +396,16 @@ _nc_first_db(DBDIRS * state, int *offset) void _nc_db_iterator_leaks(void) { + DBDIRS which; + if (my_blob != 0) FreeAndNull(my_blob); if (my_list != 0) FreeAndNull(my_list); + for (which = 0; (int) which < dbdLAST; ++which) { + my_vars[which].name = 0; + FreeIfNeeded(my_vars[which].value); + my_vars[which].value = 0; + } } #endif