From: Mikko Rasa Date: Sun, 7 Nov 2010 14:26:27 +0000 (+0000) Subject: Prevent segfault if an exception is thrown while loading X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=fb99a77241a34bce0531f21504053ddb87c8df35;p=r2c2.git Prevent segfault if an exception is thrown while loading --- diff --git a/source/libmarklin/catalogue.cpp b/source/libmarklin/catalogue.cpp index 97a91e2..82dde18 100644 --- a/source/libmarklin/catalogue.cpp +++ b/source/libmarklin/catalogue.cpp @@ -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 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 veh = new VehicleType(art_nr); load_sub(*veh); - obj.add_vehicle(*veh); - veh.release(); + obj.add_vehicle(*veh.release()); } } // namespace Marklin