From fb99a77241a34bce0531f21504053ddb87c8df35 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 7 Nov 2010 14:26:27 +0000 Subject: [PATCH] Prevent segfault if an exception is thrown while loading --- source/libmarklin/catalogue.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 -- 2.45.2