]> git.tdb.fi Git - r2c2.git/commitdiff
Plug several memory leaks
authorMikko Rasa <tdb@tdb.fi>
Sat, 25 May 2013 23:13:33 +0000 (02:13 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 25 May 2013 23:13:33 +0000 (02:13 +0300)
source/3d/layout.cpp
source/3d/tracktype.cpp
source/3d/tracktype.h
source/libr2c2/catalogue.cpp
source/libr2c2/layout.cpp

index bd59e126a91befd5a87ce1678a76cca91df1c257..d243374de5f7df4eed4a66931711b43dd201041c 100644 (file)
@@ -33,6 +33,8 @@ Layout3D::Layout3D(Layout &l):
 
 Layout3D::~Layout3D()
 {
+       while(!signals.empty())
+               delete signals.begin()->second;
        while(!tracks.empty())
                delete tracks.begin()->second;
        while(!vehicles.empty())
index 6dfd2a4f86c166cbb9b336b8cdbcaa42e45ba592..e402c89c5f597823e6daabde9943ef27b30d72bb 100644 (file)
@@ -12,7 +12,8 @@ namespace R2C2 {
 TrackType3D::TrackType3D(Catalogue3D &cat3d, const TrackType &tt):
        catalogue(cat3d),
        mesh(0),
-       object(0)
+       object(0),
+       own_data(false)
 {
        const Catalogue &cat = cat3d.get_catalogue();
        const vector<TrackPart> &parts = tt.get_parts();
@@ -53,6 +54,8 @@ TrackType3D::TrackType3D(Catalogue3D &cat3d, const TrackType &tt):
                object = new GL::Object;
                object->set_mesh(mesh);
                object->set_technique(&catalogue.get<GL::Technique>(cat.get_track_technique()));
+
+               own_data = true;
        }
  
        unsigned paths = tt.get_paths();
@@ -76,6 +79,11 @@ TrackType3D::~TrackType3D()
 {
        for(vector<GL::Mesh *>::iterator i=path_meshes.begin(); i!=path_meshes.end(); ++i)
                delete *i;
+       if(own_data)
+       {
+               delete object;
+               delete mesh;
+       }
 }
 
 const GL::Mesh &TrackType3D::get_path_mesh(unsigned p) const
index ca999c3ee2a1200e11e47e98a01419a020945f0b..952e8986b17365ee52112fd25a03b9b02e4f0c86 100644 (file)
@@ -17,6 +17,7 @@ private:
        Catalogue3D &catalogue;
        Msp::GL::Mesh *mesh;
        Msp::GL::Object *object;
+       bool own_data;
        std::vector<Msp::GL::Mesh *> path_meshes;
 
 public:
index 9310c4c91ea567e60d89b151668aec11b1cdcc13..0d62d72a85c6076eabc85cf4c0a4c5708596848c 100644 (file)
@@ -21,6 +21,8 @@ Catalogue::~Catalogue()
 {
        for(TrackMap::iterator i=tracks.begin(); i!=tracks.end(); ++i)
                delete i->second;
+       for(SignalMap::iterator i=signals.begin(); i!=signals.end(); ++i)
+               delete i->second;
        for(VehicleMap::iterator i=vehicles.begin(); i!=vehicles.end(); ++i)
                delete i->second;
 }
index c70ebb7b3879f0d528c5864bb594712093869d72..302f13a55e1d7f8d4b6d7e5f58097092fe19d075 100644 (file)
@@ -50,6 +50,8 @@ Layout::~Layout()
                delete *routes.begin();
        while(!zones.empty())
                delete *zones.begin();
+       while(!signals.empty())
+               delete *signals.begin();
        while(!tracks.empty())
                delete *tracks.begin();
        while(!blocks.empty())