From 0ddb263bbd9a8e0d0aa213ce39c0acbf8df413d5 Mon Sep 17 00:00:00 2001 From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org> Date: Tue, 28 Apr 2009 09:44:50 +0800 Subject: [PATCH] BUG: remove memory leak --- Code/IO/otbVectorDataKeywordlist.cxx | 7 ++++++- Code/IO/otbVectorDataKeywordlist.h | 12 +++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Code/IO/otbVectorDataKeywordlist.cxx b/Code/IO/otbVectorDataKeywordlist.cxx index 2e41cc11fd..8e276f148b 100644 --- a/Code/IO/otbVectorDataKeywordlist.cxx +++ b/Code/IO/otbVectorDataKeywordlist.cxx @@ -34,6 +34,10 @@ VectorDataKeywordlist { for (unsigned int i = 0; i < m_FieldList.size(); ++i) { + if (m_FieldList[i].first->GetType() == OFTString) + { + CPLFree( m_FieldList[i].second.String ); + } delete(m_FieldList[i].first); } } @@ -46,7 +50,8 @@ void VectorDataKeywordlist:: newField.second = *field; //TODO: evaluate performance impact of fieldDefn copy // the object itself could be handle at the VectorData level - // keeping only pointer here. + // keeping only pointer here. (but it does not seem + // necessary so far...) m_FieldList.push_back(CopyOgrField(newField)); }; diff --git a/Code/IO/otbVectorDataKeywordlist.h b/Code/IO/otbVectorDataKeywordlist.h index ebba3e089b..606ee31b6c 100644 --- a/Code/IO/otbVectorDataKeywordlist.h +++ b/Code/IO/otbVectorDataKeywordlist.h @@ -44,15 +44,6 @@ class VectorDataKeywordlist public: /** Smart pointer typedef support. */ typedef VectorDataKeywordlist Self; -// typedef itk::LightObject Superclass; -// typedef itk::SmartPointer<Self> Pointer; -// typedef itk::SmartPointer<const Self> ConstPointer; -// -// /** Method for creation through the object factory. */ -// itkNewMacro(Self); -// -// /** Run-time type information (and related methods). */ -// itkTypeMacro(VectorDataKeywordlist, LightObject); typedef std::pair<OGRFieldDefn*,OGRField> FieldType; typedef std::vector< FieldType > FieldListType; @@ -65,7 +56,10 @@ class VectorDataKeywordlist VectorDataKeywordlist(); virtual ~VectorDataKeywordlist(); + /** Constructor by copy (deep copy)*/ VectorDataKeywordlist(const Self&); + + /** Deep copy operator*/ void operator=(const Self&); protected: -- GitLab