From c507554935e3c793dd810e3a11cd32b39934fd74 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Thu, 5 Jan 2017 08:58:58 -0600 Subject: Clean up valgrind memory leak --- tools/test/misc/clear_open_chk.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/tools/test/misc/clear_open_chk.c b/tools/test/misc/clear_open_chk.c index f3e6ba3..67b5634 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(); + return(EXIT_FAILURE); } /* Get the file name */ @@ -56,14 +56,16 @@ 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); + return 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"); + return EXIT_FAILURE; } /* Return success */ -- cgit v0.12 From e16bfa859c45291df18a4fc203c9f036d796d4f1 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Thu, 5 Jan 2017 09:02:13 -0600 Subject: Fix valgrind memory leak --- tools/src/misc/h5clear.c | 58 +++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/tools/src/misc/h5clear.c b/tools/src/misc/h5clear.c index 0be4f8f..89dd4bd 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 * *------------------------------------------------------------------------- */ @@ -48,11 +48,11 @@ leave(int ret) } /* leave() */ /*------------------------------------------------------------------------- - * Function: usage + * Function: usage * - * Purpose: Prints a usage message + * Purpose: Prints a usage message * - * Return: void + * Return: void * *------------------------------------------------------------------------- */ @@ -66,28 +66,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,9 +100,6 @@ 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"); @@ -112,25 +109,30 @@ main (int argc, char *argv[]) /* 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"); + exit(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); + exit(EXIT_FAILURE); } + HDfree(fname); /* Close the file */ if(H5Fclose(fid) < 0) { - error_msg("H5Fclose\n"); - exit(EXIT_FAILURE); + error_msg("H5Fclose\n"); + exit(EXIT_FAILURE); } /* CLose the property list */ if(H5Pclose(fapl) < 0) { - error_msg("H5Pclose\n"); - exit(EXIT_FAILURE); + error_msg("H5Pclose\n"); + exit(EXIT_FAILURE); } return EXIT_SUCCESS; -- cgit v0.12 From cdda9c0a6a673314e4aac9ed5f49b3f69e9ad6da Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Thu, 5 Jan 2017 12:01:10 -0600 Subject: Corrected return calls --- tools/src/misc/h5clear.c | 13 ++++++------- tools/src/misc/h5mkgrp.c | 3 --- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/tools/src/misc/h5clear.c b/tools/src/misc/h5clear.c index 89dd4bd..481c6db 100644 --- a/tools/src/misc/h5clear.c +++ b/tools/src/misc/h5clear.c @@ -44,7 +44,6 @@ leave(int ret) { h5tools_close(); HDexit(ret); - } /* leave() */ /*------------------------------------------------------------------------- @@ -103,14 +102,14 @@ main (int argc, char *argv[]) /* 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); + leave(EXIT_FAILURE); } /* Duplicate the file name */ @@ -119,21 +118,21 @@ main (int argc, char *argv[]) if((fid = h5tools_fopen(fname, H5F_ACC_RDWR, fapl, NULL, NULL, (size_t)0)) < 0) { error_msg("h5tools_fopen\n"); HDfree(fname); - exit(EXIT_FAILURE); + leave(EXIT_FAILURE); } HDfree(fname); /* Close the file */ if(H5Fclose(fid) < 0) { error_msg("H5Fclose\n"); - exit(EXIT_FAILURE); + leave(EXIT_FAILURE); } /* CLose the property list */ if(H5Pclose(fapl) < 0) { error_msg("H5Pclose\n"); - exit(EXIT_FAILURE); + 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() */ -- cgit v0.12 From b3c2354a1b1a26307082c5295b83248b7dd234c1 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Thu, 5 Jan 2017 12:01:45 -0600 Subject: Corrected return calls from main() --- tools/test/misc/clear_open_chk.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/test/misc/clear_open_chk.c b/tools/test/misc/clear_open_chk.c index 67b5634..23f58bf 100644 --- a/tools/test/misc/clear_open_chk.c +++ b/tools/test/misc/clear_open_chk.c @@ -48,7 +48,7 @@ main(int argc, char *argv[]) /* Check the # of arguments */ if(argc != 2) { usage(); - return(EXIT_FAILURE); + HDexit(EXIT_FAILURE); } /* Get the file name */ @@ -58,17 +58,16 @@ main(int argc, char *argv[]) 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"); HDfree(fname); - return EXIT_FAILURE; + 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; + HDexit(EXIT_FAILURE); } /* Return success */ - return EXIT_SUCCESS; - + HDexit(EXIT_SUCCESS); } /* main() */ -- cgit v0.12