allocating and freeing memory for hdf5-specific attribute info

This commit is contained in:
Ed Hartnett 2018-11-07 13:45:51 -07:00
parent 9929e7acf9
commit 11d725facc
5 changed files with 17 additions and 3 deletions

View File

@ -131,7 +131,7 @@ typedef struct NC_ATT_INFO
nc_bool_t created; /* True if attribute already created */
nc_type nc_typeid; /* netCDF type of attribute's data */
hid_t native_hdf_typeid; /* Native HDF5 datatype for attribute's data */
void *format_dim_info;
void *format_att_info;
void *data;
nc_vlen_t *vldata; /* only used for vlen */
char **stdata; /* only for string type. */

View File

@ -451,7 +451,11 @@ nc4_put_att(NC_GRP_INFO_T* grp, int varid, const char *name, nc_type file_type,
{
LOG((3, "adding attribute %s to the list...", norm_name));
if ((ret = nc4_att_list_add(attlist, norm_name, &att)))
BAIL (ret);
BAIL(ret);
/* Allocate storage for the HDF5 specific att info. */
if (!(att->format_att_info = calloc(1, sizeof(NC_HDF5_ATT_INFO_T))))
BAIL(NC_ENOMEM);
}
/* Now fill in the metadata. */

View File

@ -507,9 +507,11 @@ nc4_rec_grp_HDF5_del(NC_GRP_INFO_T *grp)
i))))
return retval;
/* Close HDF5 resources associated with attributes. */
/* Close HDF5 resources associated with global attributes. */
for (a = 0; a < ncindexsize(grp->att); a++)
{
NC_HDF5_ATT_INFO_T hdf5_att;
att = (NC_ATT_INFO_T *)ncindexith(grp->att, a);
assert(att);

View File

@ -1593,6 +1593,10 @@ att_read_callbk(hid_t loc_id, const char *att_name, const H5A_info_t *ainfo,
if ((retval = nc4_att_list_add(list, att_name, &att)))
BAIL(-1);
/* Allocate storage for the HDF5 specific att info. */
if (!(att->format_att_info = calloc(1, sizeof(NC_HDF5_ATT_INFO_T))))
BAIL(-1);
/* Open the att by name. */
if ((attid = H5Aopen(loc_id, att_name, H5P_DEFAULT)) < 0)
BAIL(-1);

View File

@ -1143,6 +1143,10 @@ att_free(NC_ATT_INFO_T *att)
free(att->vldata);
}
/* Free any format-sepecific info. */
if (att->format_att_info)
free(att->format_att_info);
free(att);
return NC_NOERR;
}