Author: cazfi Date: Mon Mar 16 21:34:46 2015 New Revision: 28565 URL: http://svn.gna.org/viewcvs/freeciv?rev=28565&view=rev Log: Free data directory name strvecs on exit
See patch #5808 Modified: branches/S2_5/client/client_main.c branches/S2_5/common/fc_interface.c branches/S2_5/common/fc_interface.h branches/S2_5/server/srv_main.c branches/S2_5/tools/civmanual.c branches/S2_5/tools/modinst.c branches/S2_5/utility/shared.c branches/S2_5/utility/shared.h Modified: branches/S2_5/client/client_main.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/client_main.c?rev=28565&r1=28564&r2=28565&view=diff ============================================================================== --- branches/S2_5/client/client_main.c (original) +++ branches/S2_5/client/client_main.c Mon Mar 16 21:34:46 2015 @@ -656,6 +656,7 @@ conn_list_destroy(game.est_connections); registry_module_close(); + free_libfreeciv(); free_nls(); backtrace_deinit(); Modified: branches/S2_5/common/fc_interface.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/fc_interface.c?rev=28565&r1=28564&r2=28565&view=diff ============================================================================== --- branches/S2_5/common/fc_interface.c (original) +++ branches/S2_5/common/fc_interface.c Mon Mar 16 21:34:46 2015 @@ -63,3 +63,11 @@ setup_real_activities_array(); } + +/************************************************************************** + Free misc resources allocated for libfreeciv. +**************************************************************************/ +void free_libfreeciv(void) +{ + free_data_dir_names(); +} Modified: branches/S2_5/common/fc_interface.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/fc_interface.h?rev=28565&r1=28564&r2=28565&view=diff ============================================================================== --- branches/S2_5/common/fc_interface.h (original) +++ branches/S2_5/common/fc_interface.h Mon Mar 16 21:34:46 2015 @@ -40,6 +40,7 @@ struct functions *fc_interface_funcs(void); void fc_interface_init(void); +void free_libfreeciv(void); #ifdef __cplusplus } Modified: branches/S2_5/server/srv_main.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/srv_main.c?rev=28565&r1=28564&r2=28565&view=diff ============================================================================== --- branches/S2_5/server/srv_main.c (original) +++ branches/S2_5/server/srv_main.c Mon Mar 16 21:34:46 2015 @@ -1422,6 +1422,7 @@ timing_log_free(); registry_module_close(); fc_destroy_mutex(&game.server.mutexes.city_list); + free_libfreeciv(); free_nls(); con_log_close(); exit(EXIT_SUCCESS); Modified: branches/S2_5/tools/civmanual.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/tools/civmanual.c?rev=28565&r1=28564&r2=28565&view=diff ============================================================================== --- branches/S2_5/tools/civmanual.c (original) +++ branches/S2_5/tools/civmanual.c Mon Mar 16 21:34:46 2015 @@ -39,6 +39,7 @@ #include "connection.h" #include "events.h" #include "fc_cmdhelp.h" +#include "fc_interface.h" #include "fc_types.h" /* LINE_BREAK */ #include "game.h" #include "government.h" @@ -618,6 +619,7 @@ con_log_close(); registry_module_close(); + free_libfreeciv(); free_nls(); return retval; Modified: branches/S2_5/tools/modinst.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/tools/modinst.c?rev=28565&r1=28564&r2=28565&view=diff ============================================================================== --- branches/S2_5/tools/modinst.c (original) +++ branches/S2_5/tools/modinst.c Mon Mar 16 21:34:46 2015 @@ -23,6 +23,9 @@ #include "netintf.h" #include "rand.h" #include "registry.h" + +/* common */ +#include "fc_interface.h" /* modinst */ #include "mpdb.h" @@ -190,5 +193,6 @@ registry_module_close(); fc_shutdown_network(); log_close(); + free_libfreeciv(); free_nls(); } Modified: branches/S2_5/utility/shared.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/utility/shared.c?rev=28565&r1=28564&r2=28565&view=diff ============================================================================== --- branches/S2_5/utility/shared.c (original) +++ branches/S2_5/utility/shared.c Mon Mar 16 21:34:46 2015 @@ -112,6 +112,10 @@ static const char base64url[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; +static struct strvec *data_dir_names = NULL; +static struct strvec *save_dir_names = NULL; +static struct strvec *scenario_dir_names = NULL; + static int compare_file_mtime_ptrs(const struct fileinfo *const *ppa, const struct fileinfo *const *ppb); @@ -932,6 +936,25 @@ } /*************************************************************************** + Free data dir name vectors. +***************************************************************************/ +void free_data_dir_names(void) +{ + if (data_dir_names != NULL) { + strvec_destroy(data_dir_names); + data_dir_names = NULL; + } + if (save_dir_names != NULL) { + strvec_destroy(save_dir_names); + save_dir_names = NULL; + } + if (scenario_dir_names != NULL) { + strvec_destroy(scenario_dir_names); + scenario_dir_names = NULL; + } +} + +/*************************************************************************** Returns a list of data directory paths, in the order in which they should be searched. These paths are specified internally or may be set as the environment variable $FREECIV_DATA PATH (a separated list of directories, @@ -945,12 +968,10 @@ ***************************************************************************/ const struct strvec *get_data_dirs(void) { - static struct strvec *dirs = NULL; - /* The first time this function is called it will search and * allocate the directory listing. Subsequently we will already * know the list and can just return it. */ - if (NULL == dirs) { + if (NULL == data_dir_names) { const char *path; if ((path = getenv(FREECIV_DATA_PATH)) && '\0' == path[0]) { @@ -966,14 +987,14 @@ FREECIV_PATH, DEFAULT_DATA_PATH); path = NULL; } - dirs = base_get_dirs(NULL != path ? path : DEFAULT_DATA_PATH); - strvec_remove_duplicate(dirs, strcmp); /* Don't set a path both. */ - strvec_iterate(dirs, dirname) { + data_dir_names = base_get_dirs(NULL != path ? path : DEFAULT_DATA_PATH); + strvec_remove_duplicate(data_dir_names, strcmp); /* Don't set a path both. */ + strvec_iterate(data_dir_names, dirname) { log_verbose("Data path component: %s", dirname); } strvec_iterate_end; } - return dirs; + return data_dir_names; } /*************************************************************************** @@ -990,12 +1011,10 @@ ***************************************************************************/ const struct strvec *get_save_dirs(void) { - static struct strvec *dirs = NULL; - /* The first time this function is called it will search and * allocate the directory listing. Subsequently we will already * know the list and can just return it. */ - if (NULL == dirs) { + if (NULL == save_dir_names) { const char *path; bool from_freeciv_path = FALSE; @@ -1016,25 +1035,25 @@ from_freeciv_path = TRUE; } } - dirs = base_get_dirs(NULL != path ? path : DEFAULT_SAVE_PATH); + save_dir_names = base_get_dirs(NULL != path ? path : DEFAULT_SAVE_PATH); if (from_freeciv_path) { /* Then also append a "/saves" suffix to every directory. */ char buf[512]; size_t i; - for (i = 0; i < strvec_size(dirs); i++) { - path = strvec_get(dirs, i); + for (i = 0; i < strvec_size(save_dir_names); i++) { + path = strvec_get(save_dir_names, i); fc_snprintf(buf, sizeof(buf), "%s/saves", path); - strvec_insert(dirs, ++i, buf); - } - } - strvec_remove_duplicate(dirs, strcmp); /* Don't set a path both. */ - strvec_iterate(dirs, dirname) { + strvec_insert(save_dir_names, ++i, buf); + } + } + strvec_remove_duplicate(save_dir_names, strcmp); /* Don't set a path both. */ + strvec_iterate(save_dir_names, dirname) { log_verbose("Save path component: %s", dirname); } strvec_iterate_end; } - return dirs; + return save_dir_names; } /*************************************************************************** @@ -1051,12 +1070,10 @@ ***************************************************************************/ const struct strvec *get_scenario_dirs(void) { - static struct strvec *dirs = NULL; - /* The first time this function is called it will search and * allocate the directory listing. Subsequently we will already * know the list and can just return it. */ - if (NULL == dirs) { + if (NULL == scenario_dir_names) { const char *path; bool from_freeciv_path = FALSE; @@ -1077,7 +1094,7 @@ from_freeciv_path = TRUE; } } - dirs = base_get_dirs(NULL != path ? path : DEFAULT_SCENARIO_PATH); + scenario_dir_names = base_get_dirs(NULL != path ? path : DEFAULT_SCENARIO_PATH); if (from_freeciv_path) { /* Then also append subdirs every directory. */ const char *subdirs[] = { @@ -1087,21 +1104,21 @@ const char **subdir; size_t i; - for (i = 0; i < strvec_size(dirs); i++) { - path = strvec_get(dirs, i); + for (i = 0; i < strvec_size(scenario_dir_names); i++) { + path = strvec_get(scenario_dir_names, i); for (subdir = subdirs; NULL != *subdir; subdir++) { fc_snprintf(buf, sizeof(buf), "%s/%s", path, *subdir); - strvec_insert(dirs, ++i, buf); + strvec_insert(scenario_dir_names, ++i, buf); } } } - strvec_remove_duplicate(dirs, strcmp); /* Don't set a path both. */ - strvec_iterate(dirs, dirname) { + strvec_remove_duplicate(scenario_dir_names, strcmp); /* Don't set a path both. */ + strvec_iterate(scenario_dir_names, dirname) { log_verbose("Scenario path component: %s", dirname); } strvec_iterate_end; } - return dirs; + return scenario_dir_names; } /*************************************************************************** Modified: branches/S2_5/utility/shared.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/utility/shared.h?rev=28565&r1=28564&r2=28565&view=diff ============================================================================== --- branches/S2_5/utility/shared.h (original) +++ branches/S2_5/utility/shared.h Mon Mar 16 21:34:46 2015 @@ -160,6 +160,8 @@ const struct strvec *get_data_dirs(void); const struct strvec *get_save_dirs(void); const struct strvec *get_scenario_dirs(void); + +void free_data_dir_names(void); struct strvec *fileinfolist(const struct strvec *dirs, const char *suffix); struct fileinfo_list *fileinfolist_infix(const struct strvec *dirs, _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits