From 9baddb96f5f116c2866494282510613686877fef Mon Sep 17 00:00:00 2001 From: Michael Behrisch Date: Sat, 23 Nov 2024 15:30:16 +0100 Subject: [PATCH] fixing memory leaks in location parsing #13 --- src/netimport/NIImporter_OpenDrive.cpp | 4 +--- src/netimport/NIImporter_SUMO.cpp | 11 +++++------ src/netimport/NIXMLNodesHandler.cpp | 1 + 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/netimport/NIImporter_OpenDrive.cpp b/src/netimport/NIImporter_OpenDrive.cpp index 31a751ec9ac..e7917216266 100644 --- a/src/netimport/NIImporter_OpenDrive.cpp +++ b/src/netimport/NIImporter_OpenDrive.cpp @@ -2688,15 +2688,13 @@ NIImporter_OpenDrive::myCharacters(int element, const std::string& cdata) { if (i != std::string::npos) { const std::string proj = cdata.substr(i); if (proj != "") { - GeoConvHelper* result = nullptr; Boundary convBoundary; Boundary origBoundary; // XXX read values from the header convBoundary.add(Position(0, 0)); origBoundary.add(Position(0, 0)); try { - result = new GeoConvHelper(proj, myOffset, origBoundary, convBoundary); - GeoConvHelper::setLoaded(*result); + GeoConvHelper::setLoaded(GeoConvHelper(proj, myOffset, origBoundary, convBoundary)); } catch (ProcessError& e) { WRITE_ERRORF(TL("Could not set projection (%). This can be ignored with --ignore-errors."), std::string(e.what())); } diff --git a/src/netimport/NIImporter_SUMO.cpp b/src/netimport/NIImporter_SUMO.cpp index 57d72e1fb53..5fa98838743 100644 --- a/src/netimport/NIImporter_SUMO.cpp +++ b/src/netimport/NIImporter_SUMO.cpp @@ -1004,13 +1004,12 @@ NIImporter_SUMO::loadLocation(const SUMOSAXAttributes& attrs, bool setLoaded) { // @todo refactor parsing of location since its duplicated in NLHandler and PCNetProjectionLoader bool ok = true; GeoConvHelper* result = nullptr; - PositionVector s = attrs.get(SUMO_ATTR_NET_OFFSET, nullptr, ok); - Boundary convBoundary = attrs.get(SUMO_ATTR_CONV_BOUNDARY, nullptr, ok); - Boundary origBoundary = attrs.get(SUMO_ATTR_ORIG_BOUNDARY, nullptr, ok); - std::string proj = attrs.get(SUMO_ATTR_ORIG_PROJ, nullptr, ok); + const Position offset = attrs.get(SUMO_ATTR_NET_OFFSET, nullptr, ok); + const Boundary convBoundary = attrs.get(SUMO_ATTR_CONV_BOUNDARY, nullptr, ok); + const Boundary origBoundary = attrs.get(SUMO_ATTR_ORIG_BOUNDARY, nullptr, ok); + const std::string proj = attrs.get(SUMO_ATTR_ORIG_PROJ, nullptr, ok); if (ok) { - Position networkOffset = s[0]; - result = new GeoConvHelper(proj, networkOffset, origBoundary, convBoundary); + result = new GeoConvHelper(proj, offset, origBoundary, convBoundary); result->resolveAbstractProjection(); if (setLoaded) { GeoConvHelper::setLoaded(*result); diff --git a/src/netimport/NIXMLNodesHandler.cpp b/src/netimport/NIXMLNodesHandler.cpp index 47d7262c0b9..21702316d28 100644 --- a/src/netimport/NIXMLNodesHandler.cpp +++ b/src/netimport/NIXMLNodesHandler.cpp @@ -66,6 +66,7 @@ NIXMLNodesHandler::myStartElement(int element, const SUMOSAXAttributes& attrs) { switch (element) { case SUMO_TAG_LOCATION: + delete myLocation; myLocation = NIImporter_SUMO::loadLocation(attrs); if (myLocation) { GeoConvHelper::setLoadedPlain(getFileName(), *myLocation);