]> git.tdb.fi Git - r2c2.git/commitdiff
Prevent segfault if an exception is thrown while loading
authorMikko Rasa <tdb@tdb.fi>
Sun, 7 Nov 2010 14:26:27 +0000 (14:26 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sun, 7 Nov 2010 14:26:27 +0000 (14:26 +0000)
source/libmarklin/catalogue.cpp

index 97a91e23ad2af63081f85b0aa7c62324e196fa29..82dde18fdf9ccf76512576dc5157517f480ffd79 100644 (file)
@@ -121,10 +121,12 @@ void Catalogue::Loader::track(unsigned art_nr)
 
 void Catalogue::Loader::track(ArticleNumber art_nr)
 {
+       if(obj.tracks.count(art_nr))
+               throw KeyError("Duplicate track type", art_nr.str());
+
        RefPtr<TrackType> trk = new TrackType(art_nr);
        load_sub(*trk);
-       obj.add_track(*trk);
-       trk.release();
+       obj.add_track(*trk.release());
 }
 
 void Catalogue::Loader::vehicle(unsigned art_nr)
@@ -134,10 +136,12 @@ void Catalogue::Loader::vehicle(unsigned art_nr)
 
 void Catalogue::Loader::vehicle(ArticleNumber art_nr)
 {
+       if(obj.vehicles.count(art_nr))
+               throw KeyError("Duplicate vehicle type", art_nr.str());
+
        RefPtr<VehicleType> veh = new VehicleType(art_nr);
        load_sub(*veh);
-       obj.add_vehicle(*veh);
-       veh.release();
+       obj.add_vehicle(*veh.release());
 }
 
 } // namespace Marklin