Author: cazfi
Date: Wed Feb 18 08:21:45 2015
New Revision: 28203

URL: http://svn.gna.org/viewcvs/freeciv?rev=28203&view=rev
Log:
Free data directory name strvecs on exit

See patch #5808

Modified:
    trunk/client/client_main.c
    trunk/common/fc_interface.c
    trunk/common/fc_interface.h
    trunk/server/srv_main.c
    trunk/tools/civmanual.c
    trunk/tools/modinst.c
    trunk/tools/ruledit/ruledit.cpp
    trunk/utility/shared.c
    trunk/utility/shared.h

Modified: trunk/client/client_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/client_main.c?rev=28203&r1=28202&r2=28203&view=diff
==============================================================================
--- trunk/client/client_main.c  (original)
+++ trunk/client/client_main.c  Wed Feb 18 08:21:45 2015
@@ -696,6 +696,7 @@
   conn_list_destroy(game.est_connections);
 
   registry_module_close();
+  free_libfreeciv();
   free_nls();
 
   backtrace_deinit();

Modified: trunk/common/fc_interface.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/fc_interface.c?rev=28203&r1=28202&r2=28203&view=diff
==============================================================================
--- trunk/common/fc_interface.c (original)
+++ trunk/common/fc_interface.c Wed Feb 18 08:21:45 2015
@@ -63,3 +63,11 @@
 
   setup_real_activities_array();
 }
+
+/**************************************************************************
+  Free misc resources allocated for libfreeciv.
+**************************************************************************/
+void free_libfreeciv(void)
+{
+  free_data_dir_names();
+}

Modified: trunk/common/fc_interface.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/fc_interface.h?rev=28203&r1=28202&r2=28203&view=diff
==============================================================================
--- trunk/common/fc_interface.h (original)
+++ trunk/common/fc_interface.h Wed Feb 18 08:21:45 2015
@@ -20,9 +20,11 @@
 /* utility */
 #include "support.h"
 
+/* common */
+#include "vision.h"
+
 struct player;
 struct tile;
-enum vision_layer;
 struct color;
 struct extra_type;
 
@@ -41,6 +43,7 @@
 
 struct functions *fc_interface_funcs(void);
 void fc_interface_init(void);
+void free_libfreeciv(void);
 
 #ifdef __cplusplus
 }

Modified: trunk/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/srv_main.c?rev=28203&r1=28202&r2=28203&view=diff
==============================================================================
--- trunk/server/srv_main.c     (original)
+++ trunk/server/srv_main.c     Wed Feb 18 08:21:45 2015
@@ -1602,6 +1602,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: trunk/tools/civmanual.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/civmanual.c?rev=28203&r1=28202&r2=28203&view=diff
==============================================================================
--- trunk/tools/civmanual.c     (original)
+++ trunk/tools/civmanual.c     Wed Feb 18 08:21:45 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"
@@ -628,6 +629,7 @@
 
   con_log_close();
   registry_module_close();
+  free_libfreeciv();
   free_nls();
 
   return retval;

Modified: trunk/tools/modinst.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/modinst.c?rev=28203&r1=28202&r2=28203&view=diff
==============================================================================
--- trunk/tools/modinst.c       (original)
+++ trunk/tools/modinst.c       Wed Feb 18 08:21:45 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: trunk/tools/ruledit/ruledit.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/ruledit.cpp?rev=28203&r1=28202&r2=28203&view=diff
==============================================================================
--- trunk/tools/ruledit/ruledit.cpp     (original)
+++ trunk/tools/ruledit/ruledit.cpp     Wed Feb 18 08:21:45 2015
@@ -26,6 +26,7 @@
 
 /* common */
 #include "fc_cmdhelp.h"
+#include "fc_interface.h"
 #include "version.h"
 
 /* server */
@@ -93,6 +94,7 @@
 
   registry_module_close();
   log_close();
+  free_libfreeciv();
   free_nls();
 
   return EXIT_SUCCESS;

Modified: trunk/utility/shared.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/shared.c?rev=28203&r1=28202&r2=28203&view=diff
==============================================================================
--- trunk/utility/shared.c      (original)
+++ trunk/utility/shared.c      Wed Feb 18 08:21:45 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: trunk/utility/shared.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/shared.h?rev=28203&r1=28202&r2=28203&view=diff
==============================================================================
--- trunk/utility/shared.h      (original)
+++ trunk/utility/shared.h      Wed Feb 18 08:21:45 2015
@@ -154,6 +154,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

Reply via email to