summaryrefslogtreecommitdiffstats
path: root/c++/src/H5DataType.cpp
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2012-03-30 19:34:20 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2012-03-30 19:34:20 (GMT)
commit56d950d3264aae3d935854470a9178a333614bff (patch)
treee74485f6148c1c598b9961556820f7ddec7444f3 /c++/src/H5DataType.cpp
parent7f7b8bd9725854fc8b546bcde3252f2c8d5c5d32 (diff)
downloadhdf5-56d950d3264aae3d935854470a9178a333614bff.zip
hdf5-56d950d3264aae3d935854470a9178a333614bff.tar.gz
hdf5-56d950d3264aae3d935854470a9178a333614bff.tar.bz2
[svn-r22209] Purpose: Fixed bugs HDFFV-2761 & HDFFV-7852
Description: - Replaced PredType::NotAtexit() with PredType::AtExit(H5CPP_EXITED) and used PredType::AtExit as a flag to detect when all predefined types have been destroyed. Then, H5close will be called to terminate the library after its being re-initiated when the PredType destructors were activated. This change removed the memory leaks shown by the user's sample program in HDFFV-2761. - Added H5CPP_EXITED for PredType::AtExit to use as a flag - Rearranged constructors in CompType to fix bug HDFFV-7852 - Updated some inaccurate comments - Removed stream functions from FileAccPropList - Replaced H5_VMS with appropriate macro in H5IdComponent.cpp Platforms tested: Linux/32 2.6 (jam) Linux/64 2.6 (amani) SunOS 5.10 (linew)
Diffstat (limited to 'c++/src/H5DataType.cpp')
-rw-r--r--c++/src/H5DataType.cpp38
1 files changed, 27 insertions, 11 deletions
diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp
index 6e894dc..3edb163 100644
--- a/c++/src/H5DataType.cpp
+++ b/c++/src/H5DataType.cpp
@@ -54,12 +54,12 @@ namespace H5 {
///\param existing_id - IN: Id of the existing datatype
// Description
// Constructor creates a copy of an existing DataType using
-// its id. The argument "predefined" is default to false;
-// when a default datatype is created, this argument is set
-// to true so H5Tclose will not be called on it later. - need
-// a reassessment after changing to the new ref counting mech.
-// - BMR 5/2004
+// its id.
// Programmer Binh-Minh Ribler - 2000
+// Modification
+// Dec, 2005
+// Removed second argument, "predefined", after changing to the
+// new ref counting mechanism that relies on C's ref counting.
//--------------------------------------------------------------------------
DataType::DataType(const hid_t existing_id) : H5Object()
{
@@ -792,17 +792,33 @@ void DataType::close()
// Programmer Binh-Minh Ribler - 2000
// Modification
// - Replaced resetIdComponent() with decRefCount() to use C
-// library ID reference counting mechanism - BMR, Jun 1, 2004
+// library ID reference counting mechanism - BMR, Jun 1, 2004
// - Replaced decRefCount with close() to let the C library
-// handle the reference counting - BMR, Jun 1, 2006
+// handle the reference counting - BMR, Jun 1, 2006
+// - Added the use of H5CPP_EXITED to terminate the HDF5 library
+// and elimiate previous memory leaks. See comments in the
+// header file "H5PredType.h" for details. - BMR, Mar 30, 2012
//--------------------------------------------------------------------------
DataType::~DataType()
{
- try {
- close();
- } catch (Exception close_error) {
- cerr << inMemFunc("~DataType - ") << close_error.getDetailMsg() << endl;
+ try
+ {
+ /* If this is the object AtExit, terminate the HDF5 library. This is
+ to eliminate memory leaks due to the library being re-initiated
+ (after the program has ended) and not re-terminated. */
+ if (id == H5CPP_EXITED)
+ {
+ herr_t ret_value = H5close();
+ if (ret_value == FAIL)
+ throw DataTypeIException(inMemFunc("~DataType - "), "H5close failed");
}
+ // Close the HDF5 datatype
+ else
+ close();
+ }
+ catch (Exception close_error) {
+ cerr << inMemFunc("~DataType - ") << close_error.getDetailMsg() << endl;
+ }
}
#ifndef H5_NO_NAMESPACE
} // end namespace