From bdf2711333b3c0c618dc8d7d7df95eb76ee92c18 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 16 Jul 2019 14:48:26 -0600 Subject: [PATCH 1/7] cleaned up handling of nc_file->dispatchdata in hdf4 file code --- libhdf4/hdf4file.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libhdf4/hdf4file.c b/libhdf4/hdf4file.c index 147372ac6..f44a8e88e 100644 --- a/libhdf4/hdf4file.c +++ b/libhdf4/hdf4file.c @@ -627,9 +627,8 @@ NC_HDF4_open(const char *path, int mode, int basepe, size_t *chunksizehintp, /* Add necessary structs to hold netcdf-4 file data. */ if ((retval = nc4_nc4f_list_add(nc_file, path, mode))) return retval; - nc4_info = NC4_DATA(nc_file); - assert(nc4_info && nc4_info->root_grp); - h5 = nc4_info; + h5 = (NC_FILE_INFO_T *)nc_file->dispatchdata; + assert(h5 && h5->root_grp); h5->no_write = NC_TRUE; h5->root_grp->atts_read = 1; From 3310e675677982d6252cde90f765faf9832b24a8 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 16 Jul 2019 14:54:42 -0600 Subject: [PATCH 2/7] hdf4file.c cleanup --- libhdf4/hdf4file.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libhdf4/hdf4file.c b/libhdf4/hdf4file.c index f44a8e88e..bc3c055b4 100644 --- a/libhdf4/hdf4file.c +++ b/libhdf4/hdf4file.c @@ -604,8 +604,7 @@ NC_HDF4_open(const char *path, int mode, int basepe, size_t *chunksizehintp, int32 num_datasets, num_gatts; int32 sdid; int v, a; - NC_FILE_INFO_T* nc4_info = NULL; - int retval = NC_NOERR; + int retval; /* Check inputs. */ assert(nc_file && path); From d840c1864c7d6a64da84292b08be24d4224cd249 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 16 Jul 2019 16:02:08 -0600 Subject: [PATCH 3/7] removed unused prototype --- include/nc4internal.h | 2 +- libhdf4/hdf4file.c | 4 ++++ libhdf5/hdf5file.c | 4 ++++ libsrc4/nc4internal.c | 26 ++++++++++++++++++++++---- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/include/nc4internal.h b/include/nc4internal.h index 383f8709e..e0c076aa9 100644 --- a/include/nc4internal.h +++ b/include/nc4internal.h @@ -335,7 +335,7 @@ int nc4_type_free(NC_TYPE_INFO_T *type); /* These list functions add and delete vars, atts. */ int nc4_nc4f_list_add(NC *nc, const char *path, int mode); -void nc4_file_list_del(NC *nc); +int nc4_nc4f_list_del(NC_FILE_INFO_T *h5); int nc4_var_list_add(NC_GRP_INFO_T* grp, const char* name, int ndims, NC_VAR_INFO_T **var); int nc4_var_list_add2(NC_GRP_INFO_T* grp, const char* name, diff --git a/libhdf4/hdf4file.c b/libhdf4/hdf4file.c index bc3c055b4..4e079bcfa 100644 --- a/libhdf4/hdf4file.c +++ b/libhdf4/hdf4file.c @@ -724,6 +724,10 @@ NC_HDF4_close(int ncid, void *ignore) nclistfree(h5->allgroups); nclistfree(h5->alltypes); + /* Free the NC_FILE_INFO_T struct. */ + if ((retval = nc4_nc4f_list_del(h5))) + return retval; + /* Free the nc4_info struct; above code should have reclaimed everything else */ free(h5); diff --git a/libhdf5/hdf5file.c b/libhdf5/hdf5file.c index 1b110a281..a916dc0ec 100644 --- a/libhdf5/hdf5file.c +++ b/libhdf5/hdf5file.c @@ -311,6 +311,10 @@ nc4_close_netcdf4_file(NC_FILE_INFO_T *h5, int abort, NC_memio *memio) if (h5->format_file_info) free(h5->format_file_info); + /* Free the NC_FILE_INFO_T struct. */ + if ((retval = nc4_nc4f_list_del(h5))) + return retval; + /* Free the nc4_info struct; above code should have reclaimed everything else */ free(h5); diff --git a/libsrc4/nc4internal.c b/libsrc4/nc4internal.c index c86a48569..168097ea6 100644 --- a/libsrc4/nc4internal.c +++ b/libsrc4/nc4internal.c @@ -1273,13 +1273,15 @@ dim_free(NC_DIM_INFO_T *dim) * @author Dennis Heimbigner */ int -nc4_dim_list_del(NC_GRP_INFO_T* grp, NC_DIM_INFO_T *dim) +nc4_dim_list_del(NC_GRP_INFO_T *grp, NC_DIM_INFO_T *dim) { - if(grp && dim) { - int pos = ncindexfind(grp->dim,(NC_OBJ*)dim); + if (grp && dim) + { + int pos = ncindexfind(grp->dim, (NC_OBJ *)dim); if(pos >= 0) - ncindexidel(grp->dim,pos); + ncindexidel(grp->dim, pos); } + return dim_free(dim); } @@ -1364,6 +1366,22 @@ nc4_att_list_del(NCindex *list, NC_ATT_INFO_T *att) return att_free(att); } +/** + * @internal Free all resources and memory associated with a + * NC_FILE_INFO_T. + * + * @param h5 Pointer to NC_FILE_INFO_T to be freed. + * + * @return ::NC_NOERR No error. + * @author Ed Hartnett + */ +int +nc4_nc4f_list_del(NC_FILE_INFO_T *h5) +{ + assert(h5); + return NC_NOERR; +} + /** * @internal Normalize a UTF8 name. Put the result in norm_name, which * can be NC_MAX_NAME + 1 in size. This function makes sure the free() From e9666f73331b6d3c8130c4adb8ff6df4a1c2a5d7 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 16 Jul 2019 16:07:21 -0600 Subject: [PATCH 4/7] moved free(h5) intonc4_nc4f_list_del --- libhdf4/hdf4file.c | 4 ---- libhdf5/hdf5file.c | 4 ---- libsrc4/nc4internal.c | 3 +++ 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/libhdf4/hdf4file.c b/libhdf4/hdf4file.c index 4e079bcfa..cd24dda15 100644 --- a/libhdf4/hdf4file.c +++ b/libhdf4/hdf4file.c @@ -728,9 +728,5 @@ NC_HDF4_close(int ncid, void *ignore) if ((retval = nc4_nc4f_list_del(h5))) return retval; - /* Free the nc4_info struct; above code should have reclaimed - everything else */ - free(h5); - return NC_NOERR; } diff --git a/libhdf5/hdf5file.c b/libhdf5/hdf5file.c index a916dc0ec..c53802543 100644 --- a/libhdf5/hdf5file.c +++ b/libhdf5/hdf5file.c @@ -315,10 +315,6 @@ nc4_close_netcdf4_file(NC_FILE_INFO_T *h5, int abort, NC_memio *memio) if ((retval = nc4_nc4f_list_del(h5))) return retval; - /* Free the nc4_info struct; above code should have reclaimed - everything else */ - free(h5); - return NC_NOERR; } diff --git a/libsrc4/nc4internal.c b/libsrc4/nc4internal.c index 168097ea6..0c2596c28 100644 --- a/libsrc4/nc4internal.c +++ b/libsrc4/nc4internal.c @@ -1379,6 +1379,9 @@ int nc4_nc4f_list_del(NC_FILE_INFO_T *h5) { assert(h5); + + free(h5); + return NC_NOERR; } From b8e50c9254c88db9f96f1c981cecc3b0ad170921 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 16 Jul 2019 16:16:11 -0600 Subject: [PATCH 5/7] moved freeing of allvars, alldims, alltypes lists to nc4_nc4f_list_del --- libhdf4/hdf4file.c | 5 ----- libhdf5/hdf5file.c | 5 ----- libsrc4/nc4internal.c | 6 ++++++ 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/libhdf4/hdf4file.c b/libhdf4/hdf4file.c index cd24dda15..b799fa76e 100644 --- a/libhdf4/hdf4file.c +++ b/libhdf4/hdf4file.c @@ -719,11 +719,6 @@ NC_HDF4_close(int ncid, void *ignore) return NC_EHDFERR; free(hdf4_file); - /* Misc. Cleanup */ - nclistfree(h5->alldims); - nclistfree(h5->allgroups); - nclistfree(h5->alltypes); - /* Free the NC_FILE_INFO_T struct. */ if ((retval = nc4_nc4f_list_del(h5))) return retval; diff --git a/libhdf5/hdf5file.c b/libhdf5/hdf5file.c index c53802543..8d50dbb35 100644 --- a/libhdf5/hdf5file.c +++ b/libhdf5/hdf5file.c @@ -257,11 +257,6 @@ nc4_close_netcdf4_file(NC_FILE_INFO_T *h5, int abort, NC_memio *memio) if ((retval = nc4_rec_grp_del(h5->root_grp))) return retval; - /* Free lists of dims, groups, and types in the root group. */ - nclistfree(h5->alldims); - nclistfree(h5->allgroups); - nclistfree(h5->alltypes); - #ifdef USE_PARALLEL4 /* Free the MPI Comm & Info objects, if we opened the file in * parallel. */ diff --git a/libsrc4/nc4internal.c b/libsrc4/nc4internal.c index 0c2596c28..74f451e5b 100644 --- a/libsrc4/nc4internal.c +++ b/libsrc4/nc4internal.c @@ -1380,6 +1380,12 @@ nc4_nc4f_list_del(NC_FILE_INFO_T *h5) { assert(h5); + /* Cleanup these (extra) lists of all dims, groups, and types. */ + nclistfree(h5->alldims); + nclistfree(h5->allgroups); + nclistfree(h5->alltypes); + + /* Free the NC_FILE_INFO_T struct. */ free(h5); return NC_NOERR; From 4398cad8f5288bc37799a2468d351f715e3efe61 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 16 Jul 2019 16:17:07 -0600 Subject: [PATCH 6/7] whitespace cleanup --- libhdf5/hdf5file.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libhdf5/hdf5file.c b/libhdf5/hdf5file.c index 8d50dbb35..c6a9b501f 100644 --- a/libhdf5/hdf5file.c +++ b/libhdf5/hdf5file.c @@ -283,15 +283,18 @@ nc4_close_netcdf4_file(NC_FILE_INFO_T *h5, int abort, NC_memio *memio) /* If inmemory is used and user wants the final memory block, then capture and return the final memory block else free it */ - if(h5->mem.inmemory) { + if (h5->mem.inmemory) + { /* Pull out the final memory */ (void)NC4_extract_file_image(h5); - if(!abort && memio != NULL) { + if (!abort && memio != NULL) + { *memio = h5->mem.memio; /* capture it */ h5->mem.memio.memory = NULL; /* avoid duplicate free */ } /* If needed, reclaim extraneous memory */ - if(h5->mem.memio.memory != NULL) { + if (h5->mem.memio.memory != NULL) + { /* If the original block of memory is not resizeable, then it belongs to the caller and we should not free it. */ if(!h5->mem.locked) From 76d6b55eff686dc396b89fcbf21d4e435f7ae103 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 16 Jul 2019 16:29:06 -0600 Subject: [PATCH 7/7] moved call to nc4_rec_grp_del() to inside nc4_nc4f_list_del() --- libhdf4/hdf4file.c | 5 ----- libhdf5/hdf5file.c | 5 ----- libsrc4/nc4internal.c | 7 +++++++ 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/libhdf4/hdf4file.c b/libhdf4/hdf4file.c index b799fa76e..d78f59176 100644 --- a/libhdf4/hdf4file.c +++ b/libhdf4/hdf4file.c @@ -708,11 +708,6 @@ NC_HDF4_close(int ncid, void *ignore) if ((retval = hdf4_rec_grp_del(h5->root_grp))) return retval; - /* Delete all the list contents for vars, dims, and atts, in each - * group. */ - if ((retval = nc4_rec_grp_del(h5->root_grp))) - return retval; - /* Close hdf4 file and free HDF4 file info. */ hdf4_file = (NC_HDF4_FILE_INFO_T *)h5->format_file_info; if (SDend(hdf4_file->sdid)) diff --git a/libhdf5/hdf5file.c b/libhdf5/hdf5file.c index c6a9b501f..65fd033cc 100644 --- a/libhdf5/hdf5file.c +++ b/libhdf5/hdf5file.c @@ -252,11 +252,6 @@ nc4_close_netcdf4_file(NC_FILE_INFO_T *h5, int abort, NC_memio *memio) /* Get HDF5 specific info. */ hdf5_info = (NC_HDF5_FILE_INFO_T *)h5->format_file_info; - /* Delete all the list contents for vars, dims, and atts, in each - * group. */ - if ((retval = nc4_rec_grp_del(h5->root_grp))) - return retval; - #ifdef USE_PARALLEL4 /* Free the MPI Comm & Info objects, if we opened the file in * parallel. */ diff --git a/libsrc4/nc4internal.c b/libsrc4/nc4internal.c index 74f451e5b..c57a8b1b4 100644 --- a/libsrc4/nc4internal.c +++ b/libsrc4/nc4internal.c @@ -1378,8 +1378,15 @@ nc4_att_list_del(NCindex *list, NC_ATT_INFO_T *att) int nc4_nc4f_list_del(NC_FILE_INFO_T *h5) { + int retval; + assert(h5); + /* Delete all the list contents for vars, dims, and atts, in each + * group. */ + if ((retval = nc4_rec_grp_del(h5->root_grp))) + return retval; + /* Cleanup these (extra) lists of all dims, groups, and types. */ nclistfree(h5->alldims); nclistfree(h5->allgroups);