diff --git a/examples/C/vard_int.c b/examples/C/vard_int.c index a74f36a7c..5ff09e357 100644 --- a/examples/C/vard_int.c +++ b/examples/C/vard_int.c @@ -210,10 +210,11 @@ int main(int argc, char **argv) { err = ncmpi_get_vard_all(ncid, varid0, rec_filetype, buf, bufcount,buftype); ERR - err = ncmpi_close(ncid); ERR MPI_Type_free(&rec_filetype); MPI_Type_free(&fix_filetype); + err = ncmpi_close(ncid); ERR + nerrs += pnetcdf_check_mem_usage(MPI_COMM_WORLD); MPI_Finalize(); diff --git a/examples/CXX/vard_int.cpp b/examples/CXX/vard_int.cpp index ee64f8924..1f066aaf7 100644 --- a/examples/CXX/vard_int.cpp +++ b/examples/CXX/vard_int.cpp @@ -184,15 +184,15 @@ int main(int argc, char** argv) /* read the fixed-size variable */ var1.getVard_all(fix_filetype, buf, bufcount, buftype); + + MPI_Type_free(&rec_filetype); + MPI_Type_free(&fix_filetype); } catch(NcmpiException& e) { cout << e.what() << " error code=" << e.errorCode() << " Error!\n"; return 1; } - MPI_Type_free(&rec_filetype); - MPI_Type_free(&fix_filetype); - /* check if there is any PnetCDF internal malloc residue */ MPI_Offset malloc_size, sum_size; int err = ncmpi_inq_malloc_size(&malloc_size); diff --git a/examples/F77/vard_int.f b/examples/F77/vard_int.f index 9ed9126ef..d534bb217 100644 --- a/examples/F77/vard_int.f +++ b/examples/F77/vard_int.f @@ -215,13 +215,13 @@ program main + bufcount, buftype) call check(err, 'In nfmpi_get_vard_all: ') + call MPI_Type_free(rec_filetype, err) + call MPI_Type_free(fix_filetype, err) + ! close the file err = nfmpi_close(ncid) call check(err, 'In nfmpi_close: ') - call MPI_Type_free(rec_filetype, err) - call MPI_Type_free(fix_filetype, err) - ! check if there is any PnetCDF internal malloc residue 998 format(A,I13,A) err = nfmpi_inq_malloc_size(malloc_size) diff --git a/examples/F90/vard_int.f90 b/examples/F90/vard_int.f90 index 4ba1321d4..263c24bc2 100644 --- a/examples/F90/vard_int.f90 +++ b/examples/F90/vard_int.f90 @@ -202,13 +202,13 @@ program main bufcount, buftype) call check(err, 'In nf90mpi_get_vard_all: ') + call MPI_Type_free(rec_filetype, err) + call MPI_Type_free(fix_filetype, err) + ! close the file err = nf90mpi_close(ncid) call check(err, 'In nf90mpi_close: ') - call MPI_Type_free(rec_filetype, err) - call MPI_Type_free(fix_filetype, err) - ! check if there is any PnetCDF internal malloc residue 998 format(A,I13,A) err = nf90mpi_inq_malloc_size(malloc_size) diff --git a/test/largefile/large_reqs.c b/test/largefile/large_reqs.c index 300aeb33f..a0d32d9ba 100644 --- a/test/largefile/large_reqs.c +++ b/test/largefile/large_reqs.c @@ -259,10 +259,10 @@ int tst_vars(char *filename, MPI_Comm comm) err = ncmpi_wait_all(ncid, NC_REQ_ALL, NULL, NULL); CHECK_ERR - err = ncmpi_close(ncid); CHECK_ERR - MPI_Type_free(&buftype); + err = ncmpi_close(ncid); CHECK_ERR + free(varid); free(buf); diff --git a/test/testcases/flexible_api.f b/test/testcases/flexible_api.f index df67a69c6..96f318b6b 100644 --- a/test/testcases/flexible_api.f +++ b/test/testcases/flexible_api.f @@ -273,12 +273,12 @@ program main err = nfmpi_wait_all(ncid, 1, req, st) call check(err, 'In nfmpi_wait_all:') + call MPI_Type_free(subarray, err) + ! close the file err = nfmpi_close(ncid) call check(err, 'In nfmpi_close: ') - call MPI_Type_free(subarray, err) - ! check if there is any PnetCDF internal malloc residue 998 format(A,I13,A) err = nfmpi_inq_malloc_size(malloc_size) diff --git a/test/testcases/flexible_var.c b/test/testcases/flexible_var.c index 79a6c6dc5..31704f0f9 100644 --- a/test/testcases/flexible_var.c +++ b/test/testcases/flexible_var.c @@ -481,10 +481,10 @@ int main(int argc, char** argv) /* check the contents of get buffer */ CHECK_GET_BUF(NY, NX, buf) - err = ncmpi_close(ncid); CHECK_ERROUT - MPI_Type_free(&subarray); + err = ncmpi_close(ncid); CHECK_ERROUT + /* check if PnetCDF freed all internal malloc */ MPI_Offset malloc_size, sum_size; err = ncmpi_inq_malloc_size(&malloc_size); diff --git a/test/testcases/test_vard.c b/test/testcases/test_vard.c index 92eeeb6eb..9a11288cf 100644 --- a/test/testcases/test_vard.c +++ b/test/testcases/test_vard.c @@ -486,8 +486,6 @@ int main(int argc, char **argv) { } free(schar_buf); - err = ncmpi_close(ncid); CHECK_ERR - MPI_Type_free(&rec_filetype); MPI_Type_free(&fix_filetype); MPI_Type_free(&buftype); @@ -500,6 +498,8 @@ int main(int argc, char **argv) { free(flt_buf[0]); free(flt_buf); free(dbl_buf[0]); free(dbl_buf); + err = ncmpi_close(ncid); CHECK_ERR + /* check if PnetCDF freed all internal malloc */ MPI_Offset malloc_size, sum_size; err = ncmpi_inq_malloc_size(&malloc_size); diff --git a/test/testcases/test_vardf.F b/test/testcases/test_vardf.F index 80d43875b..ec04c3de3 100644 --- a/test/testcases/test_vardf.F +++ b/test/testcases/test_vardf.F @@ -392,15 +392,15 @@ program main call get_var_and_verify(ncid, varid1, NX,NY,start, count, buf, + buftype, ghost_buftype, fix_filetype, nerrs) - ! close the file - err = nfmpi_close(ncid) - call check(err, 'In nfmpi_close: ') - call MPI_Type_free(rec_filetype, ierr) call MPI_Type_free(fix_filetype, ierr) call MPI_Type_free(buftype, ierr) call MPI_Type_free(ghost_buftype, ierr) + ! close the file + err = nfmpi_close(ncid) + call check(err, 'In nfmpi_close: ') + ! check if there is any PnetCDF internal malloc residue 998 format(A,I13,A) err = nfmpi_inq_malloc_size(malloc_size) diff --git a/test/testcases/test_vardf90.f90 b/test/testcases/test_vardf90.f90 index efc13e5cc..8a78b3fdf 100644 --- a/test/testcases/test_vardf90.f90 +++ b/test/testcases/test_vardf90.f90 @@ -371,15 +371,15 @@ program main call get_var_and_verify(ncid, varid1, NX,NY,start, count, buf, & buftype, ghost_buftype, fix_filetype, nerrs) - ! close the file - err = nf90mpi_close(ncid) - call check(err, 'In nf90mpi_close: ') - call MPI_Type_free(rec_filetype, ierr) call MPI_Type_free(fix_filetype, ierr) call MPI_Type_free(buftype, ierr) call MPI_Type_free(ghost_buftype, ierr) + ! close the file + err = nf90mpi_close(ncid) + call check(err, 'In nf90mpi_close: ') + ! check if there is any PnetCDF internal malloc residue 998 format(A,I13,A) err = nfmpi_inq_malloc_size(malloc_size) diff --git a/test/testcases/vectors.c b/test/testcases/vectors.c index 159785c3c..83759a638 100644 --- a/test/testcases/vectors.c +++ b/test/testcases/vectors.c @@ -101,6 +101,9 @@ int main(int argc, char ** argv) CHECK_ERR err = ncmpi_get_vara(ncid, varid, &start, &acount, cmpbuf, 1, usertype); CHECK_ERR + + MPI_Type_free(&usertype); + err = ncmpi_close(ncid); CHECK_ERR @@ -116,7 +119,6 @@ int main(int argc, char ** argv) nerrs += errs; free(userbuf); free(cmpbuf); - MPI_Type_free(&usertype); /* check if PnetCDF freed all internal malloc */ MPI_Offset malloc_size, sum_size;