summaryrefslogtreecommitdiffstats
path: root/c++
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2014-10-02 04:32:16 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2014-10-02 04:32:16 (GMT)
commiteb20ea5379968148df2035cbebdcf3311f214717 (patch)
tree8d2752e91e039088c6e2dab032c39e60ba39d09d /c++
parent9c9326c7debc3b4f32602ec21cc67cfccafa6fc0 (diff)
downloadhdf5-eb20ea5379968148df2035cbebdcf3311f214717.zip
hdf5-eb20ea5379968148df2035cbebdcf3311f214717.tar.gz
hdf5-eb20ea5379968148df2035cbebdcf3311f214717.tar.bz2
[svn-r25655] Purpose: Fixed HDFFV-8928
Description: Followed hints from user's report on JIRA to remove several potential memory leaks. Platforms tested: Linux/ppc64 (ostrich) Linux/32 2.6 (jam) SunOS 5.11 (emu)
Diffstat (limited to 'c++')
-rw-r--r--c++/src/H5CommonFG.cpp14
-rw-r--r--c++/src/H5EnumType.cpp1
-rw-r--r--c++/src/H5Exception.cpp6
-rw-r--r--c++/src/H5IdComponent.cpp1
-rw-r--r--c++/src/H5Location.cpp1
-rw-r--r--c++/src/H5PropList.cpp1
-rw-r--r--c++/test/tfile.cpp2
7 files changed, 25 insertions, 1 deletions
diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp
index 8ee88d6..3aa0386 100644
--- a/c++/src/H5CommonFG.cpp
+++ b/c++/src/H5CommonFG.cpp
@@ -443,7 +443,10 @@ H5std_string CommonFG::getLinkval( const char* name, size_t size ) const
ret_value = H5Lget_val(getLocId(), name, value_C, val_size, H5P_DEFAULT);
if( ret_value < 0 )
+ {
+ delete []value_C;
throwException("getLinkval", "H5Lget_val failed");
+ }
value = H5std_string(value_C);
delete []value_C;
@@ -916,6 +919,12 @@ H5std_string CommonFG::getObjnameByIdx(hsize_t idx) const
name_len = H5Lget_name_by_idx(getLocId(), ".", H5_INDEX_NAME, H5_ITER_INC, idx, name_C, name_len+1, H5P_DEFAULT);
+ if (name_len < 0)
+ {
+ delete []name_C;
+ throwException("getObjnameByIdx", "H5Lget_name_by_idx failed");
+ }
+
// clean up and return the string
H5std_string name = H5std_string(name_C);
delete []name_C;
@@ -960,10 +969,15 @@ ssize_t CommonFG::getObjnameByIdx(hsize_t idx, H5std_string& name, size_t size)
char* name_C = new char[size+1]; // temporary C-string for object name
HDmemset(name_C, 0, size+1); // clear buffer
+ // call overloaded function to get the name
ssize_t name_len = getObjnameByIdx(idx, name_C, size+1);
if(name_len < 0)
+ {
+ delete []name_C;
throwException("getObjnameByIdx", "H5Lget_name_by_idx failed");
+ }
+ // clean up and return the string
name = H5std_string(name_C);
delete []name_C;
return (name_len);
diff --git a/c++/src/H5EnumType.cpp b/c++/src/H5EnumType.cpp
index 04bb9e0..a91c053 100644
--- a/c++/src/H5EnumType.cpp
+++ b/c++/src/H5EnumType.cpp
@@ -159,6 +159,7 @@ H5std_string EnumType::nameOf( void *value, size_t size ) const
// If H5Tenum_nameof returns a negative value, raise an exception,
if( ret_value < 0 )
{
+ delete []name_C;
throw DataTypeIException("EnumType::nameOf", "H5Tenum_nameof failed");
}
// otherwise, create the string to hold the datatype name and return it
diff --git a/c++/src/H5Exception.cpp b/c++/src/H5Exception.cpp
index 2d18825..daf6a74 100644
--- a/c++/src/H5Exception.cpp
+++ b/c++/src/H5Exception.cpp
@@ -80,8 +80,11 @@ H5std_string Exception::getMajorString( hid_t err_major ) const
// Check for failure again
if( mesg_size < 0 )
+ {
+ delete []mesg_C;
throw IdComponentException("Exception::getMajorString",
"H5Eget_msg failed");
+ }
// Convert the C error description and return
H5std_string major_str(mesg_C);
@@ -116,8 +119,11 @@ H5std_string Exception::getMinorString( hid_t err_minor ) const
// Check for failure again
if( mesg_size < 0 )
+ {
+ delete []mesg_C;
throw IdComponentException("Exception::getMinorString",
"H5Eget_msg failed");
+ }
// Convert the C error description and return
H5std_string minor_str(mesg_C);
diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp
index 64297ee..4a9dcac 100644
--- a/c++/src/H5IdComponent.cpp
+++ b/c++/src/H5IdComponent.cpp
@@ -317,6 +317,7 @@ H5std_string IdComponent::p_get_file_name() const
// Check for failure again
if( name_size < 0 )
{
+ delete []name_C;
throw IdComponentException("", "H5Fget_name failed");
}
diff --git a/c++/src/H5Location.cpp b/c++/src/H5Location.cpp
index 169ddf5..70be5bf 100644
--- a/c++/src/H5Location.cpp
+++ b/c++/src/H5Location.cpp
@@ -554,6 +554,7 @@ H5std_string H5Location::getComment(const char* name, size_t buf_size) const
ssize_t comment_len = getComment(name, tmp_len+1, comment_C);
if (comment_len < 0)
{
+ delete []comment_C;
throw LocationException("H5Location::getComment", "H5Oget_comment_by_name failed");
}
diff --git a/c++/src/H5PropList.cpp b/c++/src/H5PropList.cpp
index 56743f7..5afe80f 100644
--- a/c++/src/H5PropList.cpp
+++ b/c++/src/H5PropList.cpp
@@ -402,6 +402,7 @@ H5std_string PropList::getProperty(const char* name) const
// Throw exception if H5Pget returns failure
if (ret_value < 0)
{
+ delete []prop_strg_C;
throw PropListIException(inMemFunc("getProperty"), "H5Pget failed");
}
diff --git a/c++/test/tfile.cpp b/c++/test/tfile.cpp
index 2bc0d01..e4e8d34 100644
--- a/c++/test/tfile.cpp
+++ b/c++/test/tfile.cpp
@@ -598,7 +598,7 @@ static void test_file_attribute()
} // end of try block
catch (Exception E) {
- issue_fail_msg("test_file_name()", __LINE__, __FILE__, E.getCDetailMsg());
+ issue_fail_msg("test_file_attribute()", __LINE__, __FILE__, E.getCDetailMsg());
}
} // test_file_attribute()