Author: cazfi
Date: Sat Apr 11 23:03:03 2015
New Revision: 28759

URL: http://svn.gna.org/viewcvs/freeciv?rev=28759&view=rev
Log:
Free multicast group name on exit.

See patch #5989

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

Modified: branches/S2_5/common/fc_interface.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/fc_interface.c?rev=28759&r1=28758&r2=28759&view=diff
==============================================================================
--- branches/S2_5/common/fc_interface.c (original)
+++ branches/S2_5/common/fc_interface.c Sat Apr 11 23:03:03 2015
@@ -70,4 +70,5 @@
 void free_libfreeciv(void)
 {
   free_data_dir_names();
+  free_multicast_group();
 }

Modified: branches/S2_5/utility/shared.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/utility/shared.c?rev=28759&r1=28758&r2=28759&view=diff
==============================================================================
--- branches/S2_5/utility/shared.c      (original)
+++ branches/S2_5/utility/shared.c      Sat Apr 11 23:03:03 2015
@@ -115,6 +115,8 @@
 static struct strvec *data_dir_names = NULL;
 static struct strvec *save_dir_names = NULL;
 static struct strvec *scenario_dir_names = NULL;
+
+static char *mc_group = NULL;
 
 static int compare_file_mtime_ptrs(const struct fileinfo *const *ppa,
                                    const struct fileinfo *const *ppb);
@@ -1681,31 +1683,41 @@
 ***************************************************************************/
 char *get_multicast_group(bool ipv6_prefered)
 {
-  static bool init = FALSE;
-  static char *group = NULL;
   static char *default_multicast_group_ipv4 = "225.1.1.1";
 #ifdef IPV6_SUPPORT
   /* TODO: Get useful group (this is node local) */
   static char *default_multicast_group_ipv6 = "FF31::8000:15B4";
-#endif
-
-  if (!init) {
+#endif /* IPv6 support */
+
+  if (mc_group == NULL) {
     char *env = getenv("FREECIV_MULTICAST_GROUP");
+
     if (env) {
-      group = fc_strdup(env);
+      mc_group = fc_strdup(env);
     } else {
 #ifdef IPV6_SUPPORT
       if (ipv6_prefered) {
-        group = fc_strdup(default_multicast_group_ipv6);
+        mc_group = fc_strdup(default_multicast_group_ipv6);
       } else
 #endif /* IPv6 support */
       {
-        group = fc_strdup(default_multicast_group_ipv4);
-      }
-    }
-    init = TRUE;
-  }
-  return group;
+        mc_group = fc_strdup(default_multicast_group_ipv4);
+      }
+    }
+  }
+
+  return mc_group;
+}
+
+/***************************************************************************
+  Free multicast group resources
+***************************************************************************/
+void free_multicast_group(void)
+{
+  if (mc_group != NULL) {
+    free(mc_group);
+    mc_group = NULL;
+  }
 }
 
 /***************************************************************************

Modified: branches/S2_5/utility/shared.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/utility/shared.h?rev=28759&r1=28758&r2=28759&view=diff
==============================================================================
--- branches/S2_5/utility/shared.h      (original)
+++ branches/S2_5/utility/shared.h      Sat Apr 11 23:03:03 2015
@@ -215,6 +215,7 @@
                                     int *pnum_matches);
 
 char *get_multicast_group(bool ipv6_prefered);
+void free_multicast_group(void);
 void interpret_tilde(char* buf, size_t buf_size, const char* filename);
 char *interpret_tilde_alloc(const char* filename);
 char *skip_to_basename(char *filepath);


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

Reply via email to