Author: cazfi
Date: Thu Aug  6 21:12:32 2015
New Revision: 29369

URL: http://svn.gna.org/viewcvs/freeciv?rev=29369&view=rev
Log:
Free resources allocated for fileinfoname() on exit.

See patch #6170

Modified:
    branches/S2_6/common/fc_interface.c
    branches/S2_6/utility/shared.c
    branches/S2_6/utility/shared.h

Modified: branches/S2_6/common/fc_interface.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/fc_interface.c?rev=29369&r1=29368&r2=29369&view=diff
==============================================================================
--- branches/S2_6/common/fc_interface.c (original)
+++ branches/S2_6/common/fc_interface.c Thu Aug  6 21:12:32 2015
@@ -73,4 +73,5 @@
   free_data_dir_names();
   free_multicast_group();
   free_user_home_dir();
+  free_fileinfo_data();
 }

Modified: branches/S2_6/utility/shared.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/utility/shared.c?rev=29369&r1=29368&r2=29369&view=diff
==============================================================================
--- branches/S2_6/utility/shared.c      (original)
+++ branches/S2_6/utility/shared.c      Thu Aug  6 21:12:32 2015
@@ -119,6 +119,8 @@
 static char *mc_group = NULL;
 static char *home_dir = NULL;
 
+static struct astring realfile = ASTRING_INIT;
+
 static int compare_file_mtime_ptrs(const struct fileinfo *const *ppa,
                                    const struct fileinfo *const *ppb);
 
@@ -1215,11 +1217,11 @@
   read-opened.)  The returned pointer points to static memory, so this
   function can only supply one filename at a time.  Don't free that
   pointer.
+
+  TODO: Make this re-entrant
 ***************************************************************************/
 const char *fileinfoname(const struct strvec *dirs, const char *filename)
 {
-  static struct astring realfile = ASTRING_INIT;
-
   if (NULL == dirs) {
     return NULL;
   }
@@ -1236,6 +1238,7 @@
         astr_add(&realfile, "%s", dirname);
       }
     } strvec_iterate_end;
+
     return astr_str(&realfile);
   }
 
@@ -1249,7 +1252,16 @@
   } strvec_iterate_end;
 
   log_verbose("Could not find readable file \"%s\" in data path.", filename);
+
   return NULL;
+}
+
+/**************************************************************************
+  Free resources allocated for fileinfoname service
+**************************************************************************/
+void free_fileinfo_data(void)
+{
+  astr_free(&realfile);
 }
 
 /**************************************************************************

Modified: branches/S2_6/utility/shared.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/utility/shared.h?rev=29369&r1=29368&r2=29369&view=diff
==============================================================================
--- branches/S2_6/utility/shared.h      (original)
+++ branches/S2_6/utility/shared.h      Thu Aug  6 21:12:32 2015
@@ -162,6 +162,7 @@
 struct fileinfo_list *fileinfolist_infix(const struct strvec *dirs,
                                          const char *infix, bool nodups);
 const char *fileinfoname(const struct strvec *dirs, const char *filename);
+void free_fileinfo_data(void);
 
 char *get_langname(void);
 void init_nls(void);


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to