Author: suokko
Date: Wed Sep 17 12:15:10 2008
New Revision: 29514

URL: http://svn.gna.org/viewcvs/wesnoth?rev=29514&view=rev
Log:
Fixed network manager destructor not to have memory access problems.


Modified:
    branches/1.4/src/network_worker.cpp

Modified: branches/1.4/src/network_worker.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/1.4/src/network_worker.cpp?rev=29514&r1=29513&r2=29514&view=diff
==============================================================================
--- branches/1.4/src/network_worker.cpp (original)
+++ branches/1.4/src/network_worker.cpp Wed Sep 17 12:15:10 2008
@@ -135,7 +135,8 @@
 };
 
 
-bool managed = false, raw_data_only = false;
+bool volatile managed = false;
+bool raw_data_only = false;
 typedef std::vector< buffer* > buffer_set;
 buffer_set outgoing_bufs[NUM_SHARDS];
 
@@ -748,11 +749,20 @@
                                DBG_NW << "thread exited...\n";
                        }
 
+                       // Condition variables must be deleted first as
+                       // they make reference to mutexs. If the mutexs
+                       // are destroyed first, the condition variables
+                       // will access memory already freed by way of
+                       // stale mutex. Bad things will follow. ;)
+
                        threads[shard].clear();
+
+                       to_clear[shard].clear();
+
+                       delete cond[shard];
+                       cond[shard] = NULL;
                        delete shard_mutexes[shard];
                        shard_mutexes[shard] = NULL;
-                       delete cond[shard];
-                       cond[shard] = NULL;
                }
 
                delete  stats_mutex;


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to