diff --git a/Modules/IO/IOGDAL/include/otbOGRVectorDataIO.h b/Modules/IO/IOGDAL/include/otbOGRVectorDataIO.h index 45f89b75d23d1659d7d201bcaa5633d7e20f345e..9ebfd5c9a4cc96b1a6fe32eaa7ae1bd10440b5e9 100644 --- a/Modules/IO/IOGDAL/include/otbOGRVectorDataIO.h +++ b/Modules/IO/IOGDAL/include/otbOGRVectorDataIO.h @@ -19,10 +19,10 @@ #define __otbOGRVectorDataIO_h #include <string> +#include <cassert> #include "otbVectorDataIOBase.h" #include "otbVectorData.h" - #include "otbOGRVersionProxy.h" namespace otb @@ -116,6 +116,8 @@ private: std::string GetOGRDriverName(std::string name) const; + void OGRVectorDataIO::CloseInternalDataSource(); + ogr::version_proxy::GDALDatasetType * m_DataSource; }; diff --git a/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx b/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx index 75da823e3f873c64a8d7b969de141a8acd2bd290..ec46d6e2f48f22e55ac27796acc790b3305c1f56 100644 --- a/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx +++ b/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx @@ -46,7 +46,7 @@ OGRVectorDataIO::~OGRVectorDataIO() { if (m_DataSource != NULL) { - otb::ogr::version_proxy::Close(m_DataSource); + this->CloseInternalDataSource(); } } @@ -90,7 +90,7 @@ OGRVectorDataIO if (m_DataSource != NULL) { - ogr::version_proxy::Close(m_DataSource); + this->CloseInternalDataSource(); } m_DataSource = ogr::version_proxy::Open(this->m_FileName.c_str(),true); @@ -178,7 +178,13 @@ OGRVectorDataIO } // end For each layer - GDALClose(m_DataSource); + this->CloseInternalDataSource(); +} + +void OGRVectorDataIO::CloseInternalDataSource() +{ + assert(m_DataSource != NULL && "m_DataSource cannot be NULL"); + ogr::version_proxy::Close(m_DataSource); m_DataSource = NULL; }