Author: jtn
Date: Fri Dec 18 21:02:02 2015
New Revision: 31072

URL: http://svn.gna.org/viewcvs/freeciv?rev=31072&view=rev
Log:
Free packet handler hashes explicitly rather than via atexit().
This was causing the client to access freed memory on quitting a
single-player game.

See gna bug #24171.

Modified:
    trunk/client/client_main.c
    trunk/common/packets.c
    trunk/common/packets.h
    trunk/server/sernet.c

Modified: trunk/client/client_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/client_main.c?rev=31072&r1=31071&r2=31072&view=diff
==============================================================================
--- trunk/client/client_main.c  (original)
+++ trunk/client/client_main.c  Fri Dec 18 21:02:02 2015
@@ -230,6 +230,7 @@
 static void at_exit(void)
 {
   emergency_exit();
+  packets_deinit();
   fc_shutdown_network();
   update_queue_free();
   fc_destroy_ow_mutex();

Modified: trunk/common/packets.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/packets.c?rev=31072&r1=31071&r2=31072&view=diff
==============================================================================
--- trunk/common/packets.c      (original)
+++ trunk/common/packets.c      Fri Dec 18 21:02:02 2015
@@ -856,7 +856,6 @@
   /* Ensure the hash table is created. */
   if (packet_handlers == NULL) {
     packet_handlers = packet_handler_hash_new();
-    atexit(packet_handlers_free);
   }
 
   /* Lookup handlers for the capabilities or create new handlers. */
@@ -872,3 +871,12 @@
   fc_assert(phandlers != NULL);
   return phandlers;
 }
+
+/****************************************************************************
+  Call when there is no longer a requirement for protocol processing.
+  All connections must have been closed.
+****************************************************************************/
+void packets_deinit(void)
+{
+  packet_handlers_free();
+}

Modified: trunk/common/packets.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/packets.h?rev=31072&r1=31071&r2=31072&view=diff
==============================================================================
--- trunk/common/packets.h      (original)
+++ trunk/common/packets.h      Fri Dec 18 21:02:02 2015
@@ -123,6 +123,8 @@
 
 const struct packet_handlers *packet_handlers_initial(void);
 const struct packet_handlers *packet_handlers_get(const char *capability);
+
+void packets_deinit(void);
 
 #ifdef FREECIV_JSON_CONNECTION
 #include "packets_json.h"

Modified: trunk/server/sernet.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/sernet.c?rev=31072&r1=31071&r2=31072&view=diff
==============================================================================
--- trunk/server/sernet.c       (original)
+++ trunk/server/sernet.c       Fri Dec 18 21:02:02 2015
@@ -276,6 +276,7 @@
   send_server_info_to_metaserver(META_GOODBYE);
   server_close_meta();
 
+  packets_deinit();
   fc_shutdown_network();
 }
 


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

Reply via email to