From 6d247775a6b2e42de604d0e9f5b17853e5a02ad9 Mon Sep 17 00:00:00 2001 From: Neil Fortner Date: Fri, 5 May 2017 16:57:29 -0500 Subject: Fix memory leak in collective group open through soft links. Minor changes to examples. --- examples/h5dsm_dset_rpartial.c | 4 +- examples/h5dsm_ttconv.c | 88 ++++++++++++++++++++++++++++-------------- src/H5VLdaosm.c | 25 ++++++------ 3 files changed, 75 insertions(+), 42 deletions(-) diff --git a/examples/h5dsm_dset_rpartial.c b/examples/h5dsm_dset_rpartial.c index 7548e7b..aad0b2e 100644 --- a/examples/h5dsm_dset_rpartial.c +++ b/examples/h5dsm_dset_rpartial.c @@ -19,8 +19,8 @@ int main(int argc, char *argv[]) { MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); - if(mpi_size != 2) - PRINTF_ERROR("mpi_size != 2\n"); + if(mpi_size > 2) + PRINTF_ERROR("mpi_size > 2\n"); /* Seed random number generator */ srand(time(NULL)); diff --git a/examples/h5dsm_ttconv.c b/examples/h5dsm_ttconv.c index 7aa0375..731573c 100644 --- a/examples/h5dsm_ttconv.c +++ b/examples/h5dsm_ttconv.c @@ -40,8 +40,11 @@ int main(int argc, char *argv[]) { /* Seed random number generator */ srand(time(NULL)); - if(argc != 2) - PRINTF_ERROR("argc must be 2\n"); + if((argc != 2) && (argc != 3)) + PRINTF_ERROR("argc must be 2 or 3\n"); + + if(argc == 3) + verbose_g = 0; /* Parse UUID */ if(0 != uuid_parse(argv[1], pool_uuid)) @@ -273,7 +276,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* * Full write/read, with member conversion @@ -378,7 +382,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* * Write by parts @@ -445,7 +450,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* Fill buffer */ for(i = 0; i < dims[0]; i++) { @@ -509,7 +515,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* Fill buffer */ for(i = 0; i < dims[0]; i++) { @@ -573,7 +580,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* * Read by parts @@ -613,7 +621,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* Read member b */ memcpy(buf_conv, buf_conv_init, sizeof(buf_conv)); @@ -650,7 +659,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* Read member c */ memcpy(buf_conv, buf_conv_init, sizeof(buf_conv)); @@ -687,7 +697,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* * Write/read partial attributes @@ -754,7 +765,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* Fill buffer */ for(i = 0; i < dims[0]; i++) { @@ -818,7 +830,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* Fill buffer */ for(i = 0; i < dims[0]; i++) { @@ -882,7 +895,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* * Test dataset @@ -955,7 +969,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* * Full write/read, with member conversion @@ -1060,7 +1075,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* * Write by parts @@ -1127,7 +1143,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* Fill buffer */ for(i = 0; i < dims[0]; i++) { @@ -1191,7 +1208,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* Fill buffer */ for(i = 0; i < dims[0]; i++) { @@ -1255,7 +1273,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* * Read by parts @@ -1295,7 +1314,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* Read member b */ memcpy(buf_conv, buf_conv_init, sizeof(buf_conv)); @@ -1332,7 +1352,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* Read member c */ memcpy(buf_conv, buf_conv_init, sizeof(buf_conv)); @@ -1369,7 +1390,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* * Write/read partial datasets @@ -1436,7 +1458,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* Fill buffer */ for(i = 0; i < dims[0]; i++) { @@ -1500,7 +1523,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* Fill buffer */ for(i = 0; i < dims[0]; i++) { @@ -1564,7 +1588,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* * Test dataset with selections @@ -1652,7 +1677,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d does not match", i); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /*! ----------------------------------------------*/ /*! Temporary hack until overwrites are supported */ @@ -1753,7 +1779,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d, %d does not match", i, j); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /*! ----------------------------------------------*/ /*! Temporary hack until overwrites are supported */ @@ -1852,7 +1879,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d, %d does not match", i, j); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* * Partial read to contiguous buffer, member conversion to type "a" @@ -1907,7 +1935,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d, %d does not match", i, j); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* * Partial read to non-contiguous buffer, member conversion to type "a" @@ -1962,7 +1991,8 @@ int main(int argc, char *argv[]) { PRINTF_ERROR("Member c at location %d, %d does not match", i, j); } /* end for */ - printf("\n"); + if(verbose_g) + printf("\n"); /* * Close diff --git a/src/H5VLdaosm.c b/src/H5VLdaosm.c index 37556de..c7aa399 100644 --- a/src/H5VLdaosm.c +++ b/src/H5VLdaosm.c @@ -37,7 +37,7 @@ #include "H5TRprivate.h" /* Transactions */ #include "H5VLprivate.h" /* VOL plugins */ #include "H5VLdaosm.h" /* DAOS-M plugin */ - +int tmp_g=0; hid_t H5VL_DAOSM_g = -1; /* @@ -178,8 +178,7 @@ static herr_t H5VL_daosm_link_read(H5VL_daosm_group_t *grp, const char *name, static herr_t H5VL_daosm_link_write(H5VL_daosm_group_t *grp, const char *name, size_t name_len, H5VL_daosm_link_val_t *val); static herr_t H5VL_daosm_link_follow(H5VL_daosm_group_t *grp, const char *name, - size_t name_len, hid_t dxpl_id, void **req, daos_obj_id_t *oid, - void **gcpl_buf_out, uint64_t *gcpl_len_out); + size_t name_len, hid_t dxpl_id, void **req, daos_obj_id_t *oid); static H5VL_daosm_group_t *H5VL_daosm_group_traverse(H5VL_daosm_item_t *item, const char *path, hid_t dxpl_id, void **req, const char **obj_name, @@ -2381,8 +2380,7 @@ done: */ static herr_t H5VL_daosm_link_follow(H5VL_daosm_group_t *grp, const char *name, - size_t name_len, hid_t dxpl_id, void **req, daos_obj_id_t *oid, - void **gcpl_buf_out, uint64_t *gcpl_len_out) + size_t name_len, hid_t dxpl_id, void **req, daos_obj_id_t *oid) { H5VL_daosm_link_val_t link_val; hbool_t link_val_alloc = FALSE; @@ -2413,7 +2411,7 @@ H5VL_daosm_link_follow(H5VL_daosm_group_t *grp, const char *name, link_val_alloc = TRUE; /* Traverse the soft link path */ - if(NULL == (target_grp = H5VL_daosm_group_traverse(&grp->obj.item, link_val.target.soft, dxpl_id, req, &target_name, gcpl_buf_out, gcpl_len_out))) + if(NULL == (target_grp = H5VL_daosm_group_traverse(&grp->obj.item, link_val.target.soft, dxpl_id, req, &target_name, NULL, NULL))) HGOTO_ERROR(H5E_SYM, H5E_BADITER, FAIL, "can't traverse path") /* Check for no target_name, in this case just return @@ -2423,7 +2421,7 @@ H5VL_daosm_link_follow(H5VL_daosm_group_t *grp, const char *name, *oid = target_grp->obj.oid; else /* Follow the last element in the path */ - if(H5VL_daosm_link_follow(target_grp, target_name, HDstrlen(target_name), dxpl_id, req, oid, gcpl_buf_out, gcpl_len_out) < 0) + if(H5VL_daosm_link_follow(target_grp, target_name, HDstrlen(target_name), dxpl_id, req, oid) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "can't follow link") break; @@ -2507,9 +2505,13 @@ H5VL_daosm_group_traverse(H5VL_daosm_item_t *item, const char *path, /* Traverse path */ while(next_obj) { + /* Free gcpl_buf_out */ + if(gcpl_buf_out) + *gcpl_buf_out = H5MM_free(*gcpl_buf_out); + /* Follow link to next group in path */ HDassert(next_obj > *obj_name); - if(H5VL_daosm_link_follow(grp, *obj_name, (size_t)(next_obj - *obj_name), dxpl_id, req, &oid, gcpl_buf_out, gcpl_len_out) < 0) + if(H5VL_daosm_link_follow(grp, *obj_name, (size_t)(next_obj - *obj_name), dxpl_id, req, &oid) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, NULL, "can't follow link to group") /* Close previous group */ @@ -2839,6 +2841,7 @@ H5VL_daosm_group_open_helper(H5VL_daosm_file_t *file, daos_obj_id_t oid, /* Return GCPL info if requested, relinquish ownership of gcpl_buf if so */ if(gcpl_buf_out) { HDassert(gcpl_len_out); + HDassert(!*gcpl_buf_out); *gcpl_buf_out = gcpl_buf; gcpl_buf = NULL; @@ -3003,7 +3006,7 @@ H5VL_daosm_group_open(void *_item, H5VL_loc_params_t loc_params, gcpl_len = 0; /* Follow link to group */ - if(H5VL_daosm_link_follow(target_grp, target_name, HDstrlen(target_name), dxpl_id, req, &oid, NULL, NULL) < 0) + if(H5VL_daosm_link_follow(target_grp, target_name, HDstrlen(target_name), dxpl_id, req, &oid) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, NULL, "can't follow link to group") /* Open group */ @@ -3728,7 +3731,7 @@ H5VL_daosm_dataset_open(void *_item, HGOTO_ERROR(H5E_DATASET, H5E_BADITER, NULL, "can't traverse path") /* Follow link to dataset */ - if(H5VL_daosm_link_follow(target_grp, target_name, HDstrlen(target_name), dxpl_id, req, &dset->obj.oid, NULL, NULL) < 0) + if(H5VL_daosm_link_follow(target_grp, target_name, HDstrlen(target_name), dxpl_id, req, &dset->obj.oid) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "can't follow link to dataset") } /* end else */ @@ -4709,7 +4712,7 @@ H5VL_daosm_object_open(void *_item, H5VL_loc_params_t loc_params, oid = target_grp->obj.oid; else /* Follow link to object */ - if(H5VL_daosm_link_follow(target_grp, target_name, HDstrlen(target_name), dxpl_id, req, &oid, NULL, NULL) < 0) + if(H5VL_daosm_link_follow(target_grp, target_name, HDstrlen(target_name), dxpl_id, req, &oid) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "can't follow link to group") /* Broadcast group info if there are other processes that need it */ -- cgit v0.12