summaryrefslogtreecommitdiffstats
path: root/c++/src
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2012-03-23 00:50:36 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2012-03-23 00:50:36 (GMT)
commit19a6303205d070f62f2579168397579001a38fe5 (patch)
tree89d6a83a1986e44d3e51621ba98f0080eb0b7f02 /c++/src
parentc9f0f2ec22961b297d615c2deac0ce4b52a07b96 (diff)
downloadhdf5-19a6303205d070f62f2579168397579001a38fe5.zip
hdf5-19a6303205d070f62f2579168397579001a38fe5.tar.gz
hdf5-19a6303205d070f62f2579168397579001a38fe5.tar.bz2
[svn-r22128] 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')
-rw-r--r--c++/src/H5Attribute.cpp24
-rw-r--r--c++/src/H5DataSet.cpp24
2 files changed, 42 insertions, 6 deletions
diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp
index dad347f..84826c4 100644
--- a/c++/src/H5Attribute.cpp
+++ b/c++/src/H5Attribute.cpp
@@ -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);
diff --git a/c++/src/H5DataSet.cpp b/c++/src/H5DataSet.cpp
index 7351bbf..f73be0f 100644
--- a/c++/src/H5DataSet.cpp
+++ b/c++/src/H5DataSet.cpp
@@ -238,7 +238,8 @@ size_t DataSet::getInMemDataSize() const
throw DataSetIException(func, "H5Dget_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)
{
@@ -250,8 +251,19 @@ size_t DataSet::getInMemDataSize() const
throw DataSetIException(func, "H5Tget_size failed");
}
- // Get number of elements of the dataset
- hid_t space_id = H5Dget_space(id); // first get its data space
+ // Close the native type and the datatype of this dataset.
+ 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 dataset by first getting its dataspace,
+ // then getting the number of elements in the dataspace
+ hid_t space_id = H5Dget_space(id);
if (space_id < 0)
{
throw DataSetIException(func, "H5Dget_space failed");
@@ -262,6 +274,12 @@ size_t DataSet::getInMemDataSize() const
throw DataSetIException(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);