From: Mikko Rasa Date: Sat, 25 May 2013 23:13:33 +0000 (+0300) Subject: Plug several memory leaks X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=0db89b665527609582df98854c9e3255d1017811;p=r2c2.git Plug several memory leaks --- diff --git a/source/3d/layout.cpp b/source/3d/layout.cpp index bd59e12..d243374 100644 --- a/source/3d/layout.cpp +++ b/source/3d/layout.cpp @@ -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()) diff --git a/source/3d/tracktype.cpp b/source/3d/tracktype.cpp index 6dfd2a4..e402c89 100644 --- a/source/3d/tracktype.cpp +++ b/source/3d/tracktype.cpp @@ -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 &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(cat.get_track_technique())); + + own_data = true; } unsigned paths = tt.get_paths(); @@ -76,6 +79,11 @@ TrackType3D::~TrackType3D() { for(vector::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 diff --git a/source/3d/tracktype.h b/source/3d/tracktype.h index ca999c3..952e898 100644 --- a/source/3d/tracktype.h +++ b/source/3d/tracktype.h @@ -17,6 +17,7 @@ private: Catalogue3D &catalogue; Msp::GL::Mesh *mesh; Msp::GL::Object *object; + bool own_data; std::vector path_meshes; public: diff --git a/source/libr2c2/catalogue.cpp b/source/libr2c2/catalogue.cpp index 9310c4c..0d62d72 100644 --- a/source/libr2c2/catalogue.cpp +++ b/source/libr2c2/catalogue.cpp @@ -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; } diff --git a/source/libr2c2/layout.cpp b/source/libr2c2/layout.cpp index c70ebb7..302f13a 100644 --- a/source/libr2c2/layout.cpp +++ b/source/libr2c2/layout.cpp @@ -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())