summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2011-04-28 22:10:22 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2011-04-28 22:10:22 (GMT)
commitad35b2bdb2d50d8f73703742c66d5baab6481d18 (patch)
tree1018a9c5a7abc492bcd137eec794de023c4aad27
parent5d97491df4170ec4ad9ea53a0d15f13e66efb712 (diff)
downloadhdf5-ad35b2bdb2d50d8f73703742c66d5baab6481d18.zip
hdf5-ad35b2bdb2d50d8f73703742c66d5baab6481d18.tar.gz
hdf5-ad35b2bdb2d50d8f73703742c66d5baab6481d18.tar.bz2
[svn-r20673] Eliminate memory buffer errors,
overhead - add free to successful path. zip_perf - filename handling needed inits to NULL and free
-rw-r--r--perform/overhead.c306
-rw-r--r--perform/zip_perf.c18
2 files changed, 164 insertions, 160 deletions
diff --git a/perform/overhead.c b/perform/overhead.c
index cfd96b8..0c8e0ed 100644
--- a/perform/overhead.c
+++ b/perform/overhead.c
@@ -17,7 +17,7 @@
* Programmer: Robb Matzke <matzke@llnl.gov>
* Monday, September 28, 1998
*
- * Purpose: Creates a chunked dataset and measures the storage overhead.
+ * Purpose: Creates a chunked dataset and measures the storage overhead.
*/
/* See H5private.h for how to include headers */
@@ -54,12 +54,12 @@
# define UNUSED __attribute__((unused))
#endif
-#define FILE_NAME_1 "overhead.h5"
+#define FILE_NAME_1 "overhead.h5"
#ifndef FALSE
-#define FALSE 0
+#define FALSE 0
#endif /* FALSE */
#ifndef TRUE
-#define TRUE 1
+#define TRUE 1
#endif /* TRUE */
typedef enum fill_t {
@@ -73,13 +73,13 @@ typedef enum fill_t {
/*-------------------------------------------------------------------------
- * Function: usage
+ * Function: usage
*
- * Purpose: Prints a usage message and exits.
+ * Purpose: Prints a usage message and exits.
*
- * Return: never returns
+ * Return: never returns
*
- * Programmer: Robb Matzke
+ * Programmer: Robb Matzke
* Wednesday, September 30, 1998
*
* Modifications:
@@ -90,7 +90,7 @@ static void
usage(const char *prog)
{
fprintf(stderr, "usage: %s [STYLE|cache] [LEFT [MIDDLE [RIGHT]]]\n",
- prog);
+ prog);
fprintf(stderr, "\
STYLE is the order that the dataset is filled and should be one of:\n\
forward -- Fill the dataset from lowest address to highest\n\
@@ -124,13 +124,13 @@ usage(const char *prog)
/*-------------------------------------------------------------------------
- * Function: cleanup
+ * Function: cleanup
*
- * Purpose: Removes test files
+ * Purpose: Removes test files
*
- * Return: void
+ * Return: void
*
- * Programmer: Robb Matzke
+ * Programmer: Robb Matzke
* Thursday, June 4, 1998
*
* Modifications:
@@ -141,22 +141,22 @@ static void
cleanup (void)
{
if (!getenv ("HDF5_NOCLEANUP")) {
- remove (FILE_NAME_1);
+ remove (FILE_NAME_1);
}
}
/*-------------------------------------------------------------------------
- * Function: display_error_cb
+ * Function: display_error_cb
*
- * Purpose: Displays the error stack after printing "*FAILED*".
+ * Purpose: Displays the error stack after printing "*FAILED*".
*
- * Return: Success: 0
+ * Return: Success: 0
*
- * Failure: -1
+ * Failure: -1
*
- * Programmer: Robb Matzke
- * Wednesday, March 4, 1998
+ * Programmer: Robb Matzke
+ * Wednesday, March 4, 1998
*
* Modifications:
*
@@ -173,15 +173,15 @@ display_error_cb (hid_t estack, void UNUSED *client_data)
/*-------------------------------------------------------------------------
- * Function: test
+ * Function: test
*
- * Purpose: The guts of the test
+ * Purpose: The guts of the test
*
- * Return: Success: 0
+ * Return: Success: 0
*
- * Failure: number of errors
+ * Failure: number of errors
*
- * Programmer: Robb Matzke
+ * Programmer: Robb Matzke
* Wednesday, September 30, 1998
*
* Modifications:
@@ -192,25 +192,24 @@ static int
test(fill_t fill_style, const double splits[],
hbool_t verbose, hbool_t use_rdcc)
{
- hid_t file = (-1), fapl = (-1), dcpl = (-1), xfer = (-1), mspace = (-1), fspace = (-1), dset = (-1);
- hsize_t ch_size[1] = {1}; /*chunk size */
- hsize_t cur_size[1] = {1000}; /*current dataset size */
- hsize_t max_size[1] = {H5S_UNLIMITED}; /*maximum dataset size */
- hsize_t hs_start[1]; /*hyperslab start offset*/
- hsize_t hs_count[1] = {1}; /*hyperslab nelmts */
- int fd = (-1); /*h5 file direct */
- static int *had = NULL; /*for random filling */
- const char *sname=NULL; /*fill style nam */
- int mdc_nelmts; /*num meta objs to cache*/
- hsize_t i;
- int j;
- h5_stat_t sb;
+ hid_t file = (-1), fapl = (-1), dcpl = (-1), xfer = (-1), mspace = (-1), fspace = (-1), dset = (-1);
+ hsize_t ch_size[1] = {1}; /*chunk size */
+ hsize_t cur_size[1] = {1000}; /*current dataset size */
+ hsize_t max_size[1] = {H5S_UNLIMITED}; /*maximum dataset size */
+ hsize_t hs_start[1]; /*hyperslab start offset*/
+ hsize_t hs_count[1] = {1}; /*hyperslab nelmts */
+ int fd = (-1); /*h5 file direct */
+ int *had = NULL; /*for random filling */
+ const char *sname=NULL; /*fill style nam */
+ int mdc_nelmts; /*num meta objs to cache*/
+ hsize_t i;
+ int j;
+ h5_stat_t sb;
- if(!had) had = calloc((size_t)cur_size[0], sizeof(int));
if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) goto error;
if(!use_rdcc) {
- if(H5Pget_cache(fapl, &mdc_nelmts, NULL, NULL, NULL) < 0) goto error;
- if(H5Pset_cache(fapl, mdc_nelmts, 0, 0, 0.0) < 0) goto error;
+ if(H5Pget_cache(fapl, &mdc_nelmts, NULL, NULL, NULL) < 0) goto error;
+ if(H5Pset_cache(fapl, mdc_nelmts, 0, 0, 0.0) < 0) goto error;
}
if((file = H5Fcreate(FILE_NAME_1, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) goto error;
if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) goto error;
@@ -220,60 +219,63 @@ test(fill_t fill_style, const double splits[],
if((fspace = H5Screate_simple(1, cur_size, max_size)) < 0) goto error;
if((mspace = H5Screate_simple(1, ch_size, ch_size)) < 0) goto error;
if((dset = H5Dcreate2(file, "chunked", H5T_NATIVE_INT,
- fspace, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) goto error;
+ fspace, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) goto error;
if ((fd=HDopen(FILE_NAME_1, O_RDONLY, 0666)) < 0) goto error;
+ if(FILL_RANDOM==fill_style)
+ had = calloc((size_t)cur_size[0], sizeof(int));
+
for (i=1; i<=cur_size[0]; i++) {
- /* Decide which chunk to write to */
- switch (fill_style) {
- case FILL_FORWARD:
- hs_start[0] = i-1;
- break;
- case FILL_REVERSE:
- hs_start[0] = cur_size[0]-i;
- break;
- case FILL_INWARD:
- hs_start[0] = i%2 ? i/2 : cur_size[0]-i/2;
- break;
- case FILL_OUTWARD:
- j = (int)(cur_size[0]-i)+1;
- hs_start[0] = j%2 ? j/2 : (hssize_t)cur_size[0]-j/2;
- break;
- case FILL_RANDOM:
- for (j=HDrand()%(int)cur_size[0]; had[j]; j=(j+1)%(int)cur_size[0]) /*void*/;
- hs_start[0] = j;
- had[j] = 1;
- break;
- case FILL_ALL:
- abort();
- }
-
- /* Write the chunk */
- if (H5Sselect_hyperslab(fspace, H5S_SELECT_SET, hs_start, NULL,
- hs_count, NULL) < 0) goto error;
- if (H5Dwrite(dset, H5T_NATIVE_INT, mspace, fspace, xfer, &i) < 0) {
- goto error;
- }
-
-
- /* Determine overhead */
- if (verbose) {
- if (H5Fflush(file, H5F_SCOPE_LOCAL) < 0) goto error;
- if (HDfstat(fd, &sb) < 0) goto error;
- /*
- * The extra cast in the following statement is a bug workaround
- * for the Win32 version 5.0 compiler.
- * 1998-11-06 ptl
- */
- printf("%4lu %8.3f ***\n",
- (unsigned long)i,
- (double)(hssize_t)(sb.st_size-i*sizeof(int))/(hssize_t)i);
- }
-
-
+ /* Decide which chunk to write to */
+ switch (fill_style) {
+ case FILL_FORWARD:
+ hs_start[0] = i-1;
+ break;
+ case FILL_REVERSE:
+ hs_start[0] = cur_size[0]-i;
+ break;
+ case FILL_INWARD:
+ hs_start[0] = i%2 ? i/2 : cur_size[0]-i/2;
+ break;
+ case FILL_OUTWARD:
+ j = (int)(cur_size[0]-i)+1;
+ hs_start[0] = j%2 ? j/2 : (hssize_t)cur_size[0]-j/2;
+ break;
+ case FILL_RANDOM:
+ for (j=HDrand()%(int)cur_size[0]; had[j]; j=(j+1)%(int)cur_size[0]) /*void*/;
+ hs_start[0] = j;
+ had[j] = 1;
+ break;
+ case FILL_ALL:
+ abort();
+ }
+
+ /* Write the chunk */
+ if (H5Sselect_hyperslab(fspace, H5S_SELECT_SET, hs_start, NULL,
+ hs_count, NULL) < 0) goto error;
+ if (H5Dwrite(dset, H5T_NATIVE_INT, mspace, fspace, xfer, &i) < 0) {
+ goto error;
+ }
+
+ /* Determine overhead */
+ if (verbose) {
+ if (H5Fflush(file, H5F_SCOPE_LOCAL) < 0) goto error;
+ if (HDfstat(fd, &sb) < 0) goto error;
+ /*
+ * The extra cast in the following statement is a bug workaround
+ * for the Win32 version 5.0 compiler.
+ * 1998-11-06 ptl
+ */
+ printf("%4lu %8.3f ***\n",
+ (unsigned long)i,
+ (double)(hssize_t)(sb.st_size-i*sizeof(int))/(hssize_t)i);
+ }
}
+ if(had)
+ free(had);
+
H5Dclose(dset);
H5Sclose(mspace);
H5Sclose(fspace);
@@ -282,33 +284,31 @@ test(fill_t fill_style, const double splits[],
H5Fclose(file);
if (!verbose) {
- switch (fill_style) {
- case FILL_FORWARD:
- sname = "forward";
- break;
- case FILL_REVERSE:
- sname = "reverse";
- break;
- case FILL_INWARD:
- sname = "inward";
- break;
- case FILL_OUTWARD:
- sname = "outward";
- break;
- case FILL_RANDOM:
- sname = "random";
- break;
- case FILL_ALL:
- abort();
- }
-
- if (HDfstat(fd, &sb) < 0) goto error;
- printf("%-7s %8.3f\n", sname,
- (double)(hssize_t)(sb.st_size-cur_size[0]*sizeof(int))/
- (hssize_t)cur_size[0]);
+ switch (fill_style) {
+ case FILL_FORWARD:
+ sname = "forward";
+ break;
+ case FILL_REVERSE:
+ sname = "reverse";
+ break;
+ case FILL_INWARD:
+ sname = "inward";
+ break;
+ case FILL_OUTWARD:
+ sname = "outward";
+ break;
+ case FILL_RANDOM:
+ sname = "random";
+ break;
+ case FILL_ALL:
+ abort();
+ }
+
+ if (HDfstat(fd, &sb) < 0) goto error;
+ printf("%-7s %8.3f\n", sname,
+ (double)(hssize_t)(sb.st_size-cur_size[0]*sizeof(int))/
+ (hssize_t)cur_size[0]);
}
-
-
HDclose(fd);
return 0;
@@ -320,22 +320,23 @@ test(fill_t fill_style, const double splits[],
H5Pclose(dcpl);
H5Pclose(xfer);
H5Fclose(file);
- free(had);
+ if(had)
+ free(had);
HDclose(fd);
return 1;
}
/*-------------------------------------------------------------------------
- * Function: main
+ * Function: main
*
* Purpose:
*
- * Return: Success: zero
+ * Return: Success: zero
*
- * Failure: non-zero
+ * Failure: non-zero
*
- * Programmer: Robb Matzke
+ * Programmer: Robb Matzke
* Monday, September 28, 1998
*
* Modifications:
@@ -345,11 +346,11 @@ test(fill_t fill_style, const double splits[],
int
main(int argc, char *argv[])
{
- hid_t xfer;
- fill_t fill_style = FILL_ALL;
- hbool_t use_cache = FALSE;
- double splits[3];
- int i, j, nerrors=0;
+ hid_t xfer;
+ fill_t fill_style = FILL_ALL;
+ hbool_t use_cache = FALSE;
+ double splits[3];
+ int i, j, nerrors=0;
/* Default split ratios */
H5Eset_auto2(H5E_DEFAULT, display_error_cb, NULL);
@@ -360,36 +361,37 @@ main(int argc, char *argv[])
/* Parse command-line options */
for(i = 1, j = 0; i < argc; i++) {
- if (!strcmp(argv[i], "forward")) {
- fill_style = FILL_FORWARD;
- } else if (!strcmp(argv[i], "reverse")) {
- fill_style = FILL_REVERSE;
- } else if (!strcmp(argv[i], "inward")) {
- fill_style = FILL_INWARD;
- } else if (!strcmp(argv[i], "outward")) {
- fill_style = FILL_OUTWARD;
- } else if (!strcmp(argv[i], "random")) {
- fill_style = FILL_RANDOM;
- } else if (!strcmp(argv[i], "cache")) {
- use_cache = TRUE;
- } else if (j<3 && (isdigit(argv[i][0]) || '.'==argv[i][0])) {
- splits[j++] = strtod(argv[i], NULL);
- } else {
- usage(argv[0]);
- }
+ if (!strcmp(argv[i], "forward")) {
+ fill_style = FILL_FORWARD;
+ } else if (!strcmp(argv[i], "reverse")) {
+ fill_style = FILL_REVERSE;
+ } else if (!strcmp(argv[i], "inward")) {
+ fill_style = FILL_INWARD;
+ } else if (!strcmp(argv[i], "outward")) {
+ fill_style = FILL_OUTWARD;
+ } else if (!strcmp(argv[i], "random")) {
+ fill_style = FILL_RANDOM;
+ } else if (!strcmp(argv[i], "cache")) {
+ use_cache = TRUE;
+ } else if (j<3 && (isdigit(argv[i][0]) || '.'==argv[i][0])) {
+ splits[j++] = strtod(argv[i], NULL);
+ } else {
+ usage(argv[0]);
+ }
}
if (FILL_ALL==fill_style) {
- printf("%-7s %8s\n", "Style", "Bytes/Chunk");
- printf("%-7s %8s\n", "-----", "-----------");
- nerrors += test(FILL_FORWARD, splits, FALSE, use_cache);
- nerrors += test(FILL_REVERSE, splits, FALSE, use_cache);
- nerrors += test(FILL_INWARD, splits, FALSE, use_cache);
- nerrors += test(FILL_OUTWARD, splits, FALSE, use_cache);
- nerrors += test(FILL_RANDOM, splits, FALSE, use_cache);
- } else {
- if (use_cache) usage(argv[0]);
- nerrors += test(fill_style, splits, TRUE, FALSE);
+ printf("%-7s %8s\n", "Style", "Bytes/Chunk");
+ printf("%-7s %8s\n", "-----", "-----------");
+ nerrors += test(FILL_FORWARD, splits, FALSE, use_cache);
+ nerrors += test(FILL_REVERSE, splits, FALSE, use_cache);
+ nerrors += test(FILL_INWARD, splits, FALSE, use_cache);
+ nerrors += test(FILL_OUTWARD, splits, FALSE, use_cache);
+ nerrors += test(FILL_RANDOM, splits, FALSE, use_cache);
+ }
+ else {
+ if (use_cache) usage(argv[0]);
+ nerrors += test(fill_style, splits, TRUE, FALSE);
}
if (nerrors>0) goto error;
cleanup();
diff --git a/perform/zip_perf.c b/perform/zip_perf.c
index bf5f2e5..fdd824b 100644
--- a/perform/zip_perf.c
+++ b/perform/zip_perf.c
@@ -66,9 +66,9 @@
#endif
/* internal variables */
-static const char *prog;
-static const char *option_prefix;
-static char *filename;
+static const char *prog=NULL;
+static const char *option_prefix=NULL;
+static char *filename=NULL;
static int compress_percent = 0;
static int compress_level = Z_DEFAULT_COMPRESSION;
static int output, random_test = FALSE;
@@ -175,6 +175,7 @@ cleanup(void)
{
if (!getenv("HDF5_NOCLEANUP"))
unlink(filename);
+ free(filename);
}
static void
@@ -306,17 +307,18 @@ get_unique_name(void)
prefix = option_prefix;
if (prefix)
- /* 2 = 1 for '/' + 1 for null terminator */
- filename = (char *) HDmalloc(strlen(prefix) + strlen(ZIP_PERF_FILE) + 2);
+ /* 2 = 1 for '/' + 1 for null terminator */
+ filename = (char *) HDmalloc(strlen(prefix) + strlen(ZIP_PERF_FILE) + 2);
else
- filename = (char *) HDmalloc(strlen(ZIP_PERF_FILE) + 1);
+ filename = (char *) HDmalloc(strlen(ZIP_PERF_FILE) + 1);
if (!filename)
error("out of memory");
+ filename[0] = 0;
if (prefix){
- strcpy(filename, prefix);
- strcat(filename, "/");
+ strcpy(filename, prefix);
+ strcat(filename, "/");
}
strcat(filename, ZIP_PERF_FILE);
}