diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2017-01-05 18:22:06 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2017-01-05 18:22:06 (GMT) |
commit | 0f9c6ce80e0567ec6419fb434589531cda3442cc (patch) | |
tree | 19bb1e5e324c0fc34d3b09bc12d4281e4515ba6c | |
parent | 25e83ac23aaf397a924378dd31008e6a0d6677ba (diff) | |
parent | b3c2354a1b1a26307082c5295b83248b7dd234c1 (diff) | |
download | hdf5-0f9c6ce80e0567ec6419fb434589531cda3442cc.zip hdf5-0f9c6ce80e0567ec6419fb434589531cda3442cc.tar.gz hdf5-0f9c6ce80e0567ec6419fb434589531cda3442cc.tar.bz2 |
Merge pull request #237 in HDFFV/hdf5 from ~BYRN/hdf5_adb:develop to develop
* commit 'b3c2354a1b1a26307082c5295b83248b7dd234c1':
Corrected return calls from main()
Corrected return calls
Fix valgrind memory leak
Clean up valgrind memory leak
-rw-r--r-- | tools/src/misc/h5clear.c | 63 | ||||
-rw-r--r-- | tools/src/misc/h5mkgrp.c | 3 | ||||
-rw-r--r-- | tools/test/misc/clear_open_chk.c | 33 |
3 files changed, 49 insertions, 50 deletions
diff --git a/tools/src/misc/h5clear.c b/tools/src/misc/h5clear.c index 0be4f8f..481c6db 100644 --- a/tools/src/misc/h5clear.c +++ b/tools/src/misc/h5clear.c @@ -14,9 +14,9 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* - * Programmer: + * Programmer: * - * Purpose: + * Purpose: */ #include "hdf5.h" @@ -25,7 +25,7 @@ #include "h5tools_utils.h" /* Name of tool */ -#define PROGRAMNAME "h5clear" +#define PROGRAMNAME "h5clear" /* Make this private property (defined in H5Fprivate.h) available to h5clear. */ #define H5F_ACS_CLEAR_STATUS_FLAGS_NAME "clear_status_flags" @@ -35,7 +35,7 @@ * * Purpose: Close the tools library and exit * - * Return: Does not return + * Return: Does not return * *------------------------------------------------------------------------- */ @@ -44,15 +44,14 @@ leave(int ret) { h5tools_close(); HDexit(ret); - } /* leave() */ /*------------------------------------------------------------------------- - * Function: usage + * Function: usage * - * Purpose: Prints a usage message + * Purpose: Prints a usage message * - * Return: void + * Return: void * *------------------------------------------------------------------------- */ @@ -66,28 +65,28 @@ usage(void) /*------------------------------------------------------------------------- - * Function: main + * Function: main * - * Purpose: + * Purpose: * - * Return: Success: - * Failure: + * Return: Success: + * Failure: * - * Programmer: + * Programmer: * *------------------------------------------------------------------------- */ int main (int argc, char *argv[]) { - char *fname; /* File name */ - hbool_t clear = TRUE; /* To clear the status_flags in the file's superblock */ - hid_t fapl = -1; /* File access property list */ - hid_t fid = -1; /* File ID */ + char *fname; /* File name */ + hbool_t clear = TRUE; /* To clear the status_flags in the file's superblock */ + hid_t fapl = -1; /* File access property list */ + hid_t fid = -1; /* File ID */ h5tools_setprogname(PROGRAMNAME); h5tools_setstatus(EXIT_SUCCESS); - + /* Disable the HDF5 library's error reporting */ H5Eset_auto2(H5E_DEFAULT, NULL, NULL); @@ -100,38 +99,40 @@ main (int argc, char *argv[]) leave(EXIT_FAILURE); } - /* Duplicate the file name */ - fname = HDstrdup(argv[opt_ind]); - /* Get a copy of the file access property list */ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) { error_msg("H5Pcreate\n"); - exit(EXIT_FAILURE); + leave(EXIT_FAILURE); } /* Set to clear the status_flags in the file's superblock */ /* This is a private property used by h5clear only */ if(H5Pset(fapl, H5F_ACS_CLEAR_STATUS_FLAGS_NAME, &clear) < 0) { - error_msg("H5Pset\n"); - exit(EXIT_FAILURE); + error_msg("H5Pset\n"); + leave(EXIT_FAILURE); } + /* Duplicate the file name */ + fname = HDstrdup(argv[opt_ind]); + if((fid = h5tools_fopen(fname, H5F_ACC_RDWR, fapl, NULL, NULL, (size_t)0)) < 0) { - error_msg("h5tools_fopen\n"); - exit(EXIT_FAILURE); + error_msg("h5tools_fopen\n"); + HDfree(fname); + leave(EXIT_FAILURE); } + HDfree(fname); /* Close the file */ if(H5Fclose(fid) < 0) { - error_msg("H5Fclose\n"); - exit(EXIT_FAILURE); + error_msg("H5Fclose\n"); + leave(EXIT_FAILURE); } /* CLose the property list */ if(H5Pclose(fapl) < 0) { - error_msg("H5Pclose\n"); - exit(EXIT_FAILURE); + error_msg("H5Pclose\n"); + leave(EXIT_FAILURE); } - return EXIT_SUCCESS; + leave(h5tools_getstatus()); } /* main() */ diff --git a/tools/src/misc/h5mkgrp.c b/tools/src/misc/h5mkgrp.c index ad2d306..aa6057f 100644 --- a/tools/src/misc/h5mkgrp.c +++ b/tools/src/misc/h5mkgrp.c @@ -328,9 +328,6 @@ main(int argc, const char *argv[]) leave(EXIT_FAILURE); } /* end if */ - /* Shut down h5tools lib */ - h5tools_close(); - leave(EXIT_SUCCESS); } /* end main() */ diff --git a/tools/test/misc/clear_open_chk.c b/tools/test/misc/clear_open_chk.c index f3e6ba3..23f58bf 100644 --- a/tools/test/misc/clear_open_chk.c +++ b/tools/test/misc/clear_open_chk.c @@ -27,28 +27,28 @@ usage(void) } /* usage() */ /*------------------------------------------------------------------------- - * Function: main + * Function: main * - * Purpose: To open the file which has zero or nonzero status_flags in - * the superblock. + * Purpose: To open the file which has zero or nonzero status_flags in + * the superblock. * - * Return: 0 on success - * 1 on failure + * Return: 0 on success + * 1 on failure * - * Programmer: Vailin Choi; July 2013 + * Programmer: Vailin Choi; July 2013 * *------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { - char *fname; /* The HDF5 file name */ - hid_t fid; /* File ID */ + char *fname; /* The HDF5 file name */ + hid_t fid; /* File ID */ /* Check the # of arguments */ if(argc != 2) { - usage(); - return(EXIT_FAILURE); + usage(); + HDexit(EXIT_FAILURE); } /* Get the file name */ @@ -56,17 +56,18 @@ main(int argc, char *argv[]) /* Try opening the file */ if((fid = h5tools_fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT, NULL, NULL, (size_t)0)) < 0) { - HDfprintf(stderr, "clear_open_chk: unable to open the file\n"); - return EXIT_FAILURE; + HDfprintf(stderr, "clear_open_chk: unable to open the file\n"); + HDfree(fname); + HDexit(EXIT_FAILURE); } + HDfree(fname); /* Close the file */ if(H5Fclose(fid) < 0) { - HDfprintf(stderr, "clear_open_chk: cannot close the file\n"); - return EXIT_FAILURE; + HDfprintf(stderr, "clear_open_chk: cannot close the file\n"); + HDexit(EXIT_FAILURE); } /* Return success */ - return EXIT_SUCCESS; - + HDexit(EXIT_SUCCESS); } /* main() */ |