Skip to content

Commit

Permalink
Merge branch 'HDF5ImageIOMemoryLeak-for-release' into release
Browse files Browse the repository at this point in the history
Change-Id: I1f65a29576947ba949816c8755e133237a655f69
  • Loading branch information
thewtex committed May 27, 2016
2 parents 95291c3 + 760c168 commit 9c4adbb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Modules/IO/HDF5/include/itkHDF5ImageIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define itkHDF5ImageIO_h
#include "ITKIOHDF5Export.h"

#include "itkAutoPointer.h"

// itk namespace first suppresses
// kwstyle error for the H5 namespace below
Expand Down Expand Up @@ -187,6 +188,9 @@ class ITKIOHDF5_EXPORT HDF5ImageIO:public StreamingImageIOBase
unsigned long numElements);
void SetupStreaming(H5::DataSpace *imageSpace,
H5::DataSpace *slabSpace);

void CloseH5File();

H5::H5File *m_H5File;
H5::DataSet *m_VoxelDataSet;
bool m_ImageInformationWritten;
Expand Down
20 changes: 15 additions & 5 deletions Modules/IO/HDF5/src/itkHDF5ImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ HDF5ImageIO::~HDF5ImageIO()
m_VoxelDataSet->close();
delete m_VoxelDataSet;
}
if(this->m_H5File != ITK_NULLPTR)
{
this->m_H5File->close();
delete this->m_H5File;
}
this->CloseH5File();
}

void
Expand Down Expand Up @@ -690,12 +686,25 @@ ::CanReadFile(const char *FileNameToRead)
}


void
HDF5ImageIO
::CloseH5File()
{
if(this->m_H5File != ITK_NULLPTR)
{
this->m_H5File->close();
delete this->m_H5File;
}
}


void
HDF5ImageIO
::ReadImageInformation()
{
try
{
this->CloseH5File();
this->m_H5File = new H5::H5File(this->GetFileName(),
H5F_ACC_RDONLY);

Expand Down Expand Up @@ -1052,6 +1061,7 @@ ::WriteImageInformation(void)

try
{
this->CloseH5File();
this->m_H5File = new H5::H5File(this->GetFileName(),
H5F_ACC_TRUNC);
this->WriteString(ItkVersion,
Expand Down
7 changes: 6 additions & 1 deletion Modules/IO/HDF5/test/itkHDF5ImageIOTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,12 @@ int HDF5ReadWriteTest(const char *fileName)
break;
}
}
// Remove(fileName);

itk::HDF5ImageIO::Pointer io = itk::HDF5ImageIO::New();
io->SetFileName( fileName );
io->ReadImageInformation();
// Ensure there are no memory leaks
io->ReadImageInformation();
return success;
}

Expand Down

0 comments on commit 9c4adbb

Please sign in to comment.