Author: soliton
Date: Tue Apr 14 21:17:46 2009
New Revision: 34917

URL: http://svn.gna.org/viewcvs/wesnoth?rev=34917&view=rev
Log:
fixed a memory leak on advancing a game and clear the history early when saving 
a replay

Modified:
    trunk/src/server/game.cpp
    trunk/src/server/game.hpp

Modified: trunk/src/server/game.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/server/game.cpp?rev=34917&r1=34916&r2=34917&view=diff
==============================================================================
--- trunk/src/server/game.cpp (original)
+++ trunk/src/server/game.cpp Tue Apr 14 21:17:46 2009
@@ -101,9 +101,7 @@
        for (user_vector::const_iterator u = users.begin(); u != users.end(); 
++u) {
                remove_player(*u, false, true);
        }
-       for(std::vector<simple_wml::document*>::iterator i = history_.begin(); 
i != history_.end(); ++i) {
-               delete *i;
-       }
+       clear_history();
 }
 
 bool game::allow_observers() const {
@@ -192,7 +190,7 @@
        }
        end_turn_ = (turn - 1) * nsides_ + side - 1;
        end_turn();
-       history_.clear();
+       clear_history();
        if (advance) {
                // Re-assign sides to allow correct filtering of commands.
                update_side_data();
@@ -1230,7 +1228,9 @@
                                turn != turn_list.end(); ++turn) {
                        replay_commands += (*turn)->output();
                }
-       }
+               delete *i;
+       }
+       history_.clear();
 
        std::stringstream name;
        name << level_["name"] << " Turn " << current_turn();
@@ -1263,6 +1263,13 @@
 void game::record_data(simple_wml::document* data) {
        data->compress();
        history_.push_back(data);
+}
+
+void game::clear_history() {
+       for(std::vector<simple_wml::document*>::iterator i = history_.begin(); 
i != history_.end(); ++i) {
+               delete *i;
+       }
+       history_.clear();
 }
 
 void game::set_description(simple_wml::node* desc) {

Modified: trunk/src/server/game.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/server/game.hpp?rev=34917&r1=34916&r2=34917&view=diff
==============================================================================
--- trunk/src/server/game.hpp (original)
+++ trunk/src/server/game.hpp Tue Apr 14 21:17:46 2009
@@ -151,6 +151,7 @@
        void send_data(simple_wml::document& data, const network::connection 
exclude=0, std::string packet_type = "") const;
        void send_to_one(simple_wml::document& data, const network::connection 
sock, std::string packet_type = "") const;
 
+       void clear_history();
        void record_data(simple_wml::document* data);
        void save_replay();
 


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

Reply via email to