diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2012-03-23 05:43:59 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2012-03-23 05:43:59 (GMT) |
commit | 2ae01a1bf49129a3d292257fc0fad929bf7e1301 (patch) | |
tree | 21839183672ea46951808b24c7302b9fad17a81f /c++/src/H5Attribute.cpp | |
parent | b462f48e9b308886b6ed455a4aae7cbf0b8a2749 (diff) | |
download | hdf5-2ae01a1bf49129a3d292257fc0fad929bf7e1301.zip hdf5-2ae01a1bf49129a3d292257fc0fad929bf7e1301.tar.gz hdf5-2ae01a1bf49129a3d292257fc0fad929bf7e1301.tar.bz2 |
[svn-r22131] Purpose: Fixed bug 4279
Description:
Closed various HDF5 objects in DataSet::getInMemDataSize and
Attribute::getInMemDataSize to remove some memory leaks.
Platforms tested:
Linux/32 2.6 (jam)
Linux/64 2.6 (amani)
SunOS 5.10 (linew)
Diffstat (limited to 'c++/src/H5Attribute.cpp')
-rw-r--r-- | c++/src/H5Attribute.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp index 3f1e839..226ae5c 100644 --- a/c++/src/H5Attribute.cpp +++ b/c++/src/H5Attribute.cpp @@ -179,7 +179,7 @@ void Attribute::read(const DataType& mem_type, H5std_string& strg) const throw AttributeIException("Attribute::read", "H5Tis_variable_str failed"); } - if (!is_variable_len) // string is fixed length + if (!is_variable_len) // only allocate for fixed-len string { p_read_fixed_len(mem_type, strg); } @@ -198,7 +198,7 @@ void Attribute::read(const DataType& mem_type, H5std_string& strg) const //-------------------------------------------------------------------------- size_t Attribute::getInMemDataSize() const { - char *func = "Attribute::getInMemDataSize"; + const char *func = "Attribute::getInMemDataSize"; // Get the data type of this attribute hid_t mem_type_id = H5Aget_type(id); @@ -207,7 +207,8 @@ size_t Attribute::getInMemDataSize() const throw AttributeIException(func, "H5Aget_type failed"); } - // Get the data type's size + // Get the data type's size by first getting its native type then getting + // the native type's size. hid_t native_type = H5Tget_native_type(mem_type_id, H5T_DIR_DEFAULT); if (native_type < 0) { @@ -219,7 +220,18 @@ size_t Attribute::getInMemDataSize() const throw AttributeIException(func, "H5Tget_size failed"); } - // Get number of elements of the attribute + // Close the native type and the datatype of this attribute. + if (H5Tclose(native_type) < 0) + { + throw DataSetIException(func, "H5Tclose(native_type) failed"); + } + if (H5Tclose(mem_type_id) < 0) + { + throw DataSetIException(func, "H5Tclose(mem_type_id) failed"); + } + + // Get number of elements of the attribute by first getting its dataspace + // then getting the number of elements in the dataspace hid_t space_id = H5Aget_space(id); if (space_id < 0) { @@ -231,6 +243,12 @@ size_t Attribute::getInMemDataSize() const throw AttributeIException(func, "H5Sget_simple_extent_npoints failed"); } + // Close the dataspace + if (H5Sclose(space_id) < 0) + { + throw DataSetIException(func, "H5Sclose failed"); + } + // Calculate and return the size of the data size_t data_size = type_size * num_elements; return(data_size); |