Commit f7db1b98 authored by Julien Michel's avatar Julien Michel
Browse files

BUG: Fixing failing test due to unknown srs leading to segmentation fault

parent 72f6b1ff
......@@ -233,18 +233,29 @@ std::string otb::ogr::Layer::GetProjectionRef() const
{
char * wkt;
const OGRErr res = m_Layer->GetSpatialRef()->exportToWkt(&wkt);
assert(m_Layer && "OGRLayer not initialized");
OGRSpatialReference * srs = m_Layer->GetSpatialRef();
if(srs)
{
const OGRErr res = srs->exportToWkt(&wkt);
if(res != OGRERR_NONE)
{
itkGenericExceptionMacro(<< "Cannot convert spatial reference to wkt string for layer <"
<<m_Layer->GetName()<<">: " << CPLGetLastErrorMsg());
}
}
std::string stringWkt(wkt);
// According to documentation, argument of exportToWkt() should be freed
OGRFree(wkt);
// According to documentation, argument of exportToWkt() should be
// freed
if(srs)
{
CPLFree(wkt);
}
return stringWkt;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment