]> git.tdb.fi Git - r2c2.git/commitdiff
Fix valgrind warnings
authorMikko Rasa <tdb@tdb.fi>
Sun, 13 Dec 2009 14:04:42 +0000 (14:04 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sun, 13 Dec 2009 14:04:42 +0000 (14:04 +0000)
source/engineer/engineer.cpp
source/libmarklin/catalogue.cpp
source/libmarklin/control.cpp
source/libmarklin/trafficmanager.cpp

index 2c4e7263b4da113e3b304ab529e8229e5b47cebd..a2e13f10f3474f590c4e02f97ec5b117ed9d6bde 100644 (file)
@@ -112,6 +112,7 @@ Engineer::~Engineer()
        if(!simulate)
                trfc_mgr->save("engineer.state");
        delete trfc_mgr;
+       delete server;
 }
 
 void Engineer::place_train(Train &train)
@@ -179,6 +180,7 @@ int Engineer::main()
 
        Application::main();
 
+       delete root;
        delete glc;
        delete wnd;
        delete dpy;
index 689ad3b09c79e47e4db70e3ea5af8a2fa40a3f96..55a5a440a3903efbff54e86b61dc8fa7382e654d 100644 (file)
@@ -20,6 +20,8 @@ Catalogue::~Catalogue()
 {
        for(map<unsigned, TrackType *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
                delete i->second;
+       for(map<unsigned, LocoType *>::iterator i=locos.begin(); i!=locos.end(); ++i)
+               delete i->second;
 }
 
 TrackType &Catalogue::get_track(unsigned art_nr) const
index 6f7ef74dbf30bc18cd83bd111e994ef7e606c619..4f63cc20be086e90e4c56c7e2d768665444a2044 100644 (file)
@@ -36,7 +36,8 @@ Control::~Control()
                delete i->second;
        for(map<unsigned, Locomotive *>::iterator i=locomotives.begin(); i!=locomotives.end(); ++i)
                delete i->second;
-       close(serial_fd);
+       if(serial_fd>=0)
+               close(serial_fd);
 }
 
 void Control::open(const string &dev)
@@ -212,7 +213,10 @@ void Control::tick()
                if(debug)
                        cout<<"W: "<<queue.front()<<'\n';
 
-               queue.front().send(serial_fd);
+               if(serial_fd>=0)
+                       queue.front().send(serial_fd);
+               else
+                       queue.erase(queue.begin());
        }
 }
 
index b7301d3dd63e19674ebc0f0896c9aa1ce3ff6f5e..96cb269aaf37b42c8e88c7f16ff09087e59b1c33 100644 (file)
@@ -33,7 +33,8 @@ TrafficManager::TrafficManager(Control &c, Layout &l):
                if(unsigned tid=(*i)->get_turnout_id())
                        new Turnout(control, tid, (*i)->get_type().get_n_routes()>=3);
                if(unsigned sid=(*i)->get_sensor_id())
-                       new Sensor(control, sid);
+                       if(!control.get_sensors().count(sid))
+                               new Sensor(control, sid);
 
                if(used_tracks.count(*i)==0)
                {