summaryrefslogtreecommitdiffstats
path: root/c++/src/H5Attribute.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'c++/src/H5Attribute.cpp')
-rw-r--r--c++/src/H5Attribute.cpp30
1 files changed, 8 insertions, 22 deletions
diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp
index 043dc4d..1bca691 100644
--- a/c++/src/H5Attribute.cpp
+++ b/c++/src/H5Attribute.cpp
@@ -131,36 +131,22 @@ void Attribute::read( const DataType& mem_type, void *buf ) const
///\exception H5::AttributeIException
// Programmer Binh-Minh Ribler - Apr, 2003
// Modification
-// Mar 2008
-// Corrected a misunderstanding that H5Aread would allocate
-// space for the buffer. Obtained the attribute size and
-// allocated memory properly. - BMR
+// 2006/12/9 - H5Aread allocates memory for character string
+// buffer with malloc, therefore, no allocation here,
+// but HDfree is needed. - BMR
//--------------------------------------------------------------------------
void Attribute::read( const DataType& mem_type, H5std_string& strg ) const
{
- // Get the attribute size and allocate temporary C-string for C API
- hsize_t attr_size = H5Aget_storage_size(id);
- if (attr_size <= 0)
- {
- throw AttributeIException("Attribute::read", "Unable to get attribute size before reading");
- }
- char* strg_C = new char [attr_size+1];
- if (strg_C == NULL)
- {
- throw AttributeIException("Attribute::read", "Unable to allocate buffer to read the attribute");
- }
+ char* strg_C; // temporary C-string for C API
- // Call C API to get the attribute data, a string of chars
- herr_t ret_value = H5Aread(id, mem_type.getId(), &strg_C);
+ // call C API to get the attribute string of chars
+ herr_t ret_value = H5Aread( id, mem_type.getId(), &strg_C);
if( ret_value < 0 )
{
throw AttributeIException("Attribute::read", "H5Aread failed");
}
-
- // Get 'string' from the C char* and release resource
- strg_C[attr_size] = '\0';
- strg = strg_C;
- delete []strg_C;
+ strg = strg_C; // get 'string' from the C char*
+ HDfree(strg_C);
}
//--------------------------------------------------------------------------