From 4b3cb3f738e26a4ebec5f509d1af5fee1ad222ba Mon Sep 17 00:00:00 2001
From: Guillaume Pasero <guillaume.pasero@c-s.fr>
Date: Tue, 6 Feb 2018 16:00:51 +0100
Subject: [PATCH] BUG: #1504: delete SRS after usage

---
 .../include/otbPersistentSamplingFilterBase.txx      | 12 +++++++++++-
 .../test/otbImageSampleExtractorFilterTest.cxx       |  1 +
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/Modules/Learning/Sampling/include/otbPersistentSamplingFilterBase.txx b/Modules/Learning/Sampling/include/otbPersistentSamplingFilterBase.txx
index 2973a7a8a3..502438a0d2 100644
--- a/Modules/Learning/Sampling/include/otbPersistentSamplingFilterBase.txx
+++ b/Modules/Learning/Sampling/include/otbPersistentSamplingFilterBase.txx
@@ -265,6 +265,11 @@ PersistentSamplingFilterBase<TInputImage,TMaskImage>
       }
     this->m_InMemoryOutputs.push_back(tmpContainer);
     }
+
+  if (oSRS)
+    {
+    oSRS->Release();
+    }
 }
 
 template <class TInputImage, class TMaskImage>
@@ -734,7 +739,7 @@ PersistentSamplingFilterBase<TInputImage,TMaskImage>
     }
 
   const unsigned int nbFeatThread = std::ceil(inLayer.GetFeatureCount(true) / (float) numberOfThreads);
-  assert(nbFeatThread > 0);
+  //assert(nbFeatThread > 0);
 
   OGRFeatureDefn &layerDefn = inLayer.GetLayerDefn();
   ogr::Layer::const_iterator featIt = inLayer.begin();
@@ -807,6 +812,11 @@ PersistentSamplingFilterBase<TInputImage,TMaskImage>
       OGRFieldDefn fieldDefn(layerDefn.GetFieldDefn(k));
       outLayer.CreateField(fieldDefn);
       }
+
+    if (oSRS)
+      {
+      oSRS->Release();
+      }
     }
 
   // Add new fields
diff --git a/Modules/Learning/Sampling/test/otbImageSampleExtractorFilterTest.cxx b/Modules/Learning/Sampling/test/otbImageSampleExtractorFilterTest.cxx
index 138032ea73..414a773027 100644
--- a/Modules/Learning/Sampling/test/otbImageSampleExtractorFilterTest.cxx
+++ b/Modules/Learning/Sampling/test/otbImageSampleExtractorFilterTest.cxx
@@ -129,6 +129,7 @@ int otbImageSampleExtractorFilterUpdate(int argc, char* argv[])
   output->CreateLayer( inLayer.GetName(),
                        oSRS,
                        inLayer.GetLayerDefn().GetGeomType());
+  oSRS->Release();
   otb::ogr::Layer dstLayer = output->GetLayer(0);
   OGRFieldDefn labelField(classFieldName.c_str(),OFTString);
   dstLayer.CreateField(labelField, true);
-- 
GitLab