Skip to content

Commit

Permalink
fixing memory leaks in location parsing #13
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Nov 23, 2024
1 parent f310b11 commit 9baddb9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/netimport/NIImporter_OpenDrive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down
11 changes: 5 additions & 6 deletions src/netimport/NIImporter_SUMO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PositionVector>(SUMO_ATTR_NET_OFFSET, nullptr, ok);
Boundary convBoundary = attrs.get<Boundary>(SUMO_ATTR_CONV_BOUNDARY, nullptr, ok);
Boundary origBoundary = attrs.get<Boundary>(SUMO_ATTR_ORIG_BOUNDARY, nullptr, ok);
std::string proj = attrs.get<std::string>(SUMO_ATTR_ORIG_PROJ, nullptr, ok);
const Position offset = attrs.get<Position>(SUMO_ATTR_NET_OFFSET, nullptr, ok);
const Boundary convBoundary = attrs.get<Boundary>(SUMO_ATTR_CONV_BOUNDARY, nullptr, ok);
const Boundary origBoundary = attrs.get<Boundary>(SUMO_ATTR_ORIG_BOUNDARY, nullptr, ok);
const std::string proj = attrs.get<std::string>(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);
Expand Down
1 change: 1 addition & 0 deletions src/netimport/NIXMLNodesHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9baddb9

Please sign in to comment.