Skip to content

Commit

Permalink
Merge pull request #70 from softvise/fix_double_free
Browse files Browse the repository at this point in the history
Fix a double-free error with ExternalReference.
  • Loading branch information
jklimke authored Jun 27, 2022
2 parents 6e2b9c8 + 74410e2 commit 4dacf5d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion sources/include/citygml/citygmlfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace citygml {

std::shared_ptr<Polygon> createPolygon(const std::string& id);
std::shared_ptr<LineString> createLineString(const std::string& id);
std::shared_ptr<ExternalReference> createExternalReference(const std::string& id);
ExternalReference* createExternalReference(const std::string& id);

/**
* @brief requests a polygon for a Geometry object that will be added later
Expand Down
2 changes: 1 addition & 1 deletion sources/include/parser/externalreferenceparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace citygml {
virtual Object* getObject() override;

private:
std::shared_ptr<ExternalReference> model;
std::unique_ptr<ExternalReference> model;
std::function<void(ExternalReference *)> callback;
};
}
5 changes: 2 additions & 3 deletions sources/src/citygml/citygmlfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@ namespace citygml {
return std::shared_ptr<LineString>(lineString);
}

std::shared_ptr<ExternalReference> CityGMLFactory::createExternalReference(const std::string& id)
ExternalReference* CityGMLFactory::createExternalReference(const std::string& id)
{
ExternalReference * externalReference = new ExternalReference(id);
return std::shared_ptr<ExternalReference>(externalReference);
return new ExternalReference(id);
}

void CityGMLFactory::requestSharedPolygonForGeometry(Geometry* geom, const std::string& polygonId)
Expand Down
4 changes: 2 additions & 2 deletions sources/src/parser/externalreferenceparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ namespace citygml {
CITYGML_LOG_ERROR(m_logger, "Expected start tag <" << NodeType::CORE_ExternalReferenceNode << "> but got <" << node.name() << "> at " << getDocumentLocation());
}

model = m_factory.createExternalReference(attributes.getCityGMLIDAttribute());
model.reset(m_factory.createExternalReference(attributes.getCityGMLIDAttribute()));

return true;
}

bool ExternalReferenceParser::parseElementEndTag(NodeType::XMLNode const& node, std::string const&) {
callback(model.get());
callback(model.release());
return true;
}

Expand Down

0 comments on commit 4dacf5d

Please sign in to comment.