[svn-r13038] Purpose: Fixed user reported bug

Description:
    In Attribute::read, H5Aread malloc's memory for the read data buffer,
    so Attribute::read shouldn't allocate the buffer, but needs to
    deallocate with HDfree.

    Fixed a typo in H5StrType.cpp, should pass PredType::C_S1 to "copy"
    instead of H5T_C_S1.

Platforms tested:
    AIX 5.1 (copper)
    Linux 2.6 (kagiso)
    SunOS 5.8 64-bit (sol)
This commit is contained in:
Binh-Minh Ribler 2006-12-10 20:23:04 -05:00
parent 14e9b46ca2
commit c0ffce092f
2 changed files with 12 additions and 6 deletions

View File

@ -30,6 +30,7 @@
#include "H5CommonFG.h"
#include "H5DataType.h"
#include "H5DataSpace.h"
#include "H5private.h"
#ifndef H5_NO_NAMESPACE
namespace H5 {
@ -128,18 +129,23 @@ void Attribute::read( const DataType& mem_type, void *buf ) const
///\param strg - IN: Buffer for read string
///\exception H5::AttributeIException
// Programmer Binh-Minh Ribler - Apr, 2003
// Modification
// 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
{
size_t size = mem_type.getSize();
char* strg_C = new char[size+1]; // temporary C-string for C API
herr_t ret_value = H5Aread( id, mem_type.getId(), &strg_C );
char* strg_C; // temporary C-string for C API
// 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");
}
strg = strg_C;
delete []strg_C;
strg = strg_C; // get 'string' from the C char*
HDfree(strg_C);
}
//--------------------------------------------------------------------------

View File

@ -102,7 +102,7 @@ StrType::StrType( const int dummy, const size_t& size ) : AtomType()
{
// use DataType::copy to make a copy of the string predefined type
// then set its length
copy(H5T_C_S1);
copy(PredType::C_S1);
setSize(size);
}