diff options
Diffstat (limited to 'java/src/jni/h5aImp.c')
-rw-r--r-- | java/src/jni/h5aImp.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/java/src/jni/h5aImp.c b/java/src/jni/h5aImp.c index 71caf76..07ecdb8 100644 --- a/java/src/jni/h5aImp.c +++ b/java/src/jni/h5aImp.c @@ -1115,7 +1115,8 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem H5T_class_t type_class; jsize vl_array_len; htri_t vl_data_class; - herr_t status = FAIL; + herr_t status = FAIL; + htri_t is_variable = 0; UNUSED(clss); @@ -1124,10 +1125,11 @@ Java_hdf_hdf5lib_H5_H5AreadVL(JNIEnv *env, jclass clss, jlong attr_id, jlong mem if ((vl_data_class = h5str_detect_vlen(mem_type_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); - /* Get size of data array */ if ((vl_array_len = ENVPTR->GetArrayLength(ENVONLY, buf)) < 0) H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Aread: readBuf length < 0"); + if ((is_variable = H5Tis_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); if (!(typeSize = H5Tget_size(mem_type_id))) H5_LIBRARY_ERROR(ENVONLY); @@ -1154,7 +1156,10 @@ done: if (sid >= 0) H5Sclose(sid); } - + if (is_variable) { + for (size_t i = 0; i < (size_t)vl_array_len; i++) + HDfree(((char **)readBuf)[i]); + } HDfree(readBuf); } @@ -1177,7 +1182,8 @@ Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong me H5T_class_t type_class; jsize vl_array_len; htri_t vl_data_class; - herr_t status = FAIL; + herr_t status = FAIL; + htri_t is_variable = 0; UNUSED(clss); @@ -1192,6 +1198,8 @@ Java_hdf_hdf5lib_H5_H5AwriteVL(JNIEnv *env, jclass clss, jlong attr_id, jlong me CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5Awrite: write buffer length < 0"); } + if ((is_variable = H5Tis_variable_str(mem_type_id)) < 0) + H5_LIBRARY_ERROR(ENVONLY); if (!(typeSize = H5Tget_size(mem_type_id))) H5_LIBRARY_ERROR(ENVONLY); @@ -1216,6 +1224,10 @@ done: H5Treclaim(attr_id, sid, H5P_DEFAULT, writeBuf); } + if (is_variable) { + for (size_t i = 0; i < (size_t)vl_array_len; i++) + HDfree(((char **)writeBuf)[i]); + } HDfree(writeBuf); } |