diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2011-02-05 02:41:22 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2011-02-05 02:41:22 (GMT) |
commit | c087ecdbdea8f142f1a4823db71ea47fa60a8c59 (patch) | |
tree | e17f06cf2710e5524205ebd40d96b127494ddce9 /perform | |
parent | 89a47692e9d14798dd2e7506a34f74810c1259dc (diff) | |
download | hdf5-c087ecdbdea8f142f1a4823db71ea47fa60a8c59.zip hdf5-c087ecdbdea8f142f1a4823db71ea47fa60a8c59.tar.gz hdf5-c087ecdbdea8f142f1a4823db71ea47fa60a8c59.tar.bz2 |
[svn-r20048] Description:
Bring Coverity changes back to trunk:
r19733:
Fix memory leak in h5perf_serial. Global buffer "buffer2" was allocated at the
beginning of do_sio() but never freed. Added call to free() at end of do_sio().
r19734:
Fix memory leak in iopipe. Buffer "the_data" was allocated at the beginning of
main() but never freed. Added call to free() at end of main().
Tested on:
Coverity branch in daily tests & Mac
Diffstat (limited to 'perform')
-rw-r--r-- | perform/iopipe.c | 126 | ||||
-rw-r--r-- | perform/sio_engine.c | 40 |
2 files changed, 84 insertions, 82 deletions
diff --git a/perform/iopipe.c b/perform/iopipe.c index a67c5c8..c72e3aa 100644 --- a/perform/iopipe.c +++ b/perform/iopipe.c @@ -133,18 +133,10 @@ synchronize (void) { #ifdef H5_HAVE_SYSTEM #if defined(_WIN32) && ! defined(__CYGWIN__) - _flushall(); + _flushall(); #else - HDsystem ("sync"); - HDsystem ("df >/dev/null"); -#endif -#if 0 - /* - * This works well on Linux to get rid of all cached disk buffers. The - * number should be approximately the amount of RAM in MB. Do not - * include swap space in that amount or the command will fail. - */ - system ("/sbin/swapout 128"); + HDsystem("sync"); + HDsystem("df >/dev/null"); #endif #endif } @@ -170,10 +162,10 @@ int main (void) { static hsize_t size[2] = {REQUEST_SIZE_X, REQUEST_SIZE_Y}; - static int nread=NREAD_REQUESTS, nwrite=NWRITE_REQUESTS; + static unsigned nread = NREAD_REQUESTS, nwrite = NWRITE_REQUESTS; unsigned char *the_data = NULL; - hid_t file, dset, file_space=-1; + hid_t file, dset, file_space = -1; herr_t status; #ifdef H5_HAVE_GETRUSAGE struct rusage r_start, r_stop; @@ -181,7 +173,8 @@ main (void) struct timeval r_start, r_stop; #endif struct timeval t_start, t_stop; - int i, fd; + int fd; + unsigned u; hssize_t n; off_t offset; hsize_t start[2]; @@ -211,35 +204,34 @@ main (void) assert(file_space >= 0); dset = H5Dcreate2(file, "dset", H5T_NATIVE_UCHAR, file_space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); assert(dset >= 0); - the_data = malloc((size_t)(size[0] * size[1])); + the_data = (unsigned char *)malloc((size_t)(size[0] * size[1])); /* initial fill for lazy malloc */ - memset(the_data, 0xAA, (size_t)(size[0] * size[1])); + HDmemset(the_data, 0xAA, (size_t)(size[0] * size[1])); /* Fill raw */ synchronize (); #ifdef H5_HAVE_GETRUSAGE -printf("Before getrusage() call\n"); - getrusage (RUSAGE_SELF, &r_start); + HDgetrusage(RUSAGE_SELF, &r_start); #endif #ifdef H5_HAVE_GETTIMEOFDAY - gettimeofday (&t_start, NULL); + HDgettimeofday(&t_start, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstart); #endif #endif fprintf (stderr, HEADING, "fill raw"); - for (i=0; i<nwrite; i++) { + for(u = 0; u < nwrite; u++) { putc (PROGRESS, stderr); - fflush (stderr); - memset (the_data, 0xAA, (size_t)(size[0]*size[1])); + HDfflush(stderr); + HDmemset(the_data, 0xAA, (size_t)(size[0]*size[1])); } #ifdef H5_HAVE_GETRUSAGE - getrusage (RUSAGE_SELF, &r_stop); + HDgetrusage(RUSAGE_SELF, &r_stop); #endif #ifdef H5_HAVE_GETTIMEOFDAY - gettimeofday (&t_stop, NULL); + HDgettimeofday(&t_stop, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstop); @@ -258,28 +250,28 @@ printf("Before getrusage() call\n"); /* Fill hdf5 */ synchronize (); #ifdef H5_HAVE_GETRUSAGE - getrusage (RUSAGE_SELF, &r_start); + HDgetrusage(RUSAGE_SELF, &r_start); #endif #ifdef H5_HAVE_GETTIMEOFDAY - gettimeofday (&t_start, NULL); + HDgettimeofday(&t_start, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstart); #endif #endif fprintf (stderr, HEADING, "fill hdf5"); - for (i=0; i<nread; i++) { + for(u = 0; u < nread; u++) { putc (PROGRESS, stderr); - fflush (stderr); + HDfflush(stderr); status = H5Dread (dset, H5T_NATIVE_UCHAR, file_space, file_space, H5P_DEFAULT, the_data); assert (status>=0); } #ifdef H5_HAVE_GETRUSAGE - getrusage (RUSAGE_SELF, &r_stop); + HDgetrusage(RUSAGE_SELF, &r_stop); #endif #ifdef H5_HAVE_GETTIMEOFDAY - gettimeofday (&t_stop, NULL); + HDgettimeofday(&t_stop, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstop); @@ -297,29 +289,29 @@ printf("Before getrusage() call\n"); /* Write the raw dataset */ synchronize (); #ifdef H5_HAVE_GETRUSAGE - getrusage (RUSAGE_SELF, &r_start); + HDgetrusage(RUSAGE_SELF, &r_start); #endif #ifdef H5_HAVE_GETTIMEOFDAY - gettimeofday (&t_start, NULL); + HDgettimeofday(&t_start, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstart); #endif #endif fprintf (stderr, HEADING, "out raw"); - for (i=0; i<nwrite; i++) { + for(u = 0; u < nwrite; u++) { putc (PROGRESS, stderr); - fflush (stderr); + HDfflush(stderr); offset = HDlseek (fd, (off_t)0, SEEK_SET); assert (0==offset); n = HDwrite (fd, the_data, (size_t)(size[0]*size[1])); assert (n>=0 && (size_t)n==size[0]*size[1]); } #ifdef H5_HAVE_GETRUSAGE - getrusage (RUSAGE_SELF, &r_stop); + HDgetrusage(RUSAGE_SELF, &r_stop); #endif #ifdef H5_HAVE_GETTIMEOFDAY - gettimeofday (&t_stop, NULL); + HDgettimeofday(&t_stop, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstop); @@ -337,28 +329,28 @@ printf("Before getrusage() call\n"); /* Write the hdf5 dataset */ synchronize (); #ifdef H5_HAVE_GETRUSAGE - getrusage (RUSAGE_SELF, &r_start); + HDgetrusage(RUSAGE_SELF, &r_start); #endif #ifdef H5_HAVE_GETTIMEOFDAY - gettimeofday (&t_start, NULL); + HDgettimeofday(&t_start, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstart); #endif #endif fprintf (stderr, HEADING, "out hdf5"); - for (i=0; i<nwrite; i++) { + for(u = 0; u < nwrite; u++) { putc (PROGRESS, stderr); - fflush (stderr); + HDfflush(stderr); status = H5Dwrite (dset, H5T_NATIVE_UCHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT, the_data); assert (status>=0); } #ifdef H5_HAVE_GETRUSAGE - getrusage (RUSAGE_SELF, &r_stop); + HDgetrusage(RUSAGE_SELF, &r_stop); #endif #ifdef H5_HAVE_GETTIMEOFDAY - gettimeofday (&t_stop, NULL); + HDgettimeofday(&t_stop, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstop); @@ -376,29 +368,29 @@ printf("Before getrusage() call\n"); /* Read the raw dataset */ synchronize (); #ifdef H5_HAVE_GETRUSAGE - getrusage (RUSAGE_SELF, &r_start); + HDgetrusage(RUSAGE_SELF, &r_start); #endif #ifdef H5_HAVE_GETTIMEOFDAY - gettimeofday (&t_start, NULL); + HDgettimeofday(&t_start, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstart); #endif #endif fprintf (stderr, HEADING, "in raw"); - for (i=0; i<nread; i++) { + for(u = 0; u < nread; u++) { putc (PROGRESS, stderr); - fflush (stderr); + HDfflush(stderr); offset = HDlseek (fd, (off_t)0, SEEK_SET); assert (0==offset); n = HDread (fd, the_data, (size_t)(size[0]*size[1])); assert (n>=0 && (size_t)n==size[0]*size[1]); } #ifdef H5_HAVE_GETRUSAGE - getrusage (RUSAGE_SELF, &r_stop); + HDgetrusage(RUSAGE_SELF, &r_stop); #endif #ifdef H5_HAVE_GETTIMEOFDAY - gettimeofday (&t_stop, NULL); + HDgettimeofday(&t_stop, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstop); @@ -417,28 +409,28 @@ printf("Before getrusage() call\n"); /* Read the hdf5 dataset */ synchronize (); #ifdef H5_HAVE_GETRUSAGE - getrusage (RUSAGE_SELF, &r_start); + HDgetrusage(RUSAGE_SELF, &r_start); #endif #ifdef H5_HAVE_GETTIMEOFDAY - gettimeofday (&t_start, NULL); + HDgettimeofday(&t_start, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstart); #endif #endif fprintf (stderr, HEADING, "in hdf5"); - for (i=0; i<nread; i++) { + for(u = 0; u < nread; u++) { putc (PROGRESS, stderr); - fflush (stderr); + HDfflush(stderr); status = H5Dread (dset, H5T_NATIVE_UCHAR, file_space, file_space, H5P_DEFAULT, the_data); assert (status>=0); } #ifdef H5_HAVE_GETRUSAGE - getrusage (RUSAGE_SELF, &r_stop); + HDgetrusage(RUSAGE_SELF, &r_stop); #endif #ifdef H5_HAVE_GETTIMEOFDAY - gettimeofday (&t_stop, NULL); + HDgettimeofday(&t_stop, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstop); @@ -461,28 +453,28 @@ printf("Before getrusage() call\n"); assert (status>=0); synchronize (); #ifdef H5_HAVE_GETRUSAGE - getrusage (RUSAGE_SELF, &r_start); + HDgetrusage(RUSAGE_SELF, &r_start); #endif #ifdef H5_HAVE_GETTIMEOFDAY - gettimeofday (&t_start, NULL); + HDgettimeofday(&t_start, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstart); #endif #endif fprintf (stderr, HEADING, "in hdf5 partial"); - for (i=0; i<nread; i++) { + for(u = 0; u < nread; u++) { putc (PROGRESS, stderr); - fflush (stderr); + HDfflush(stderr); status = H5Dread (dset, H5T_NATIVE_UCHAR, file_space, file_space, H5P_DEFAULT, the_data); assert (status>=0); } #ifdef H5_HAVE_GETRUSAGE - getrusage (RUSAGE_SELF, &r_stop); + HDgetrusage(RUSAGE_SELF, &r_stop); #endif #ifdef H5_HAVE_GETTIMEOFDAY - gettimeofday (&t_stop, NULL); + HDgettimeofday(&t_stop, NULL); #else #ifdef H5_HAVE_SYS_TIMEB _ftime(tbstop); @@ -492,18 +484,20 @@ printf("Before getrusage() call\n"); t_stop.tv_usec = tbstop->millitm; #endif #endif - putc ('\n', stderr); - print_stats ("in hdf5 partial", + putc('\n', stderr); + print_stats("in hdf5 partial", &r_start, &r_stop, &t_start, &t_stop, (size_t)(nread*count[0]*count[1])); /* Close everything */ - HDclose (fd); - H5Dclose (dset); - H5Sclose (file_space); - H5Fclose (file); + HDclose(fd); + H5Dclose(dset); + H5Sclose(file_space); + H5Fclose(file); + free(the_data); return 0; } + diff --git a/perform/sio_engine.c b/perform/sio_engine.c index 978ac03..e892bcc 100644 --- a/perform/sio_engine.c +++ b/perform/sio_engine.c @@ -98,7 +98,7 @@ static herr_t do_write(results *res, file_descr *fd, parameters *parms, void *bu static herr_t do_read(results *res, file_descr *fd, parameters *parms, void *buffer); static herr_t dset_write(int local_dim, file_descr *fd, parameters *parms, void *buffer); static herr_t posix_buffer_write(int local_dim, file_descr *fd, parameters *parms, void *buffer); -static herr_t dset_read(int localrank, file_descr *fd, parameters *parms, void *buffer); +static herr_t dset_read(int localrank, file_descr *fd, parameters *parms, void *buffer, const char *buffer2); static herr_t posix_buffer_read(int local_dim, file_descr *fd, parameters *parms, void *buffer); static herr_t do_fopen(parameters *param, char *fname, file_descr *fd /*out*/, int flags); @@ -130,7 +130,6 @@ static size_t cont_size; /* size of contiguous POSIX access */ static hid_t fapl; /* file access list */ static unsigned char *buf_p; /* buffer pointer */ static const char *multi_letters = "msbrglo"; /* string for multi driver */ -static char *buffer2=NULL; /* buffer for data verification */ /* HDF5 global variables */ static hsize_t h5count[MAX_DIMS]; /*selection count */ @@ -212,10 +211,8 @@ do_sio(parameters param) } /* Allocate transfer buffer */ - buffer2 = malloc(linear_buf_size); if ((buffer = malloc(linear_buf_size)) == NULL){ - HDfprintf(stderr, "malloc for transfer buffer size (%Hd) failed\n", - (long long)(linear_buf_size)); + HDfprintf(stderr, "malloc for transfer buffer size (%Hd) failed\n", (long long)(linear_buf_size)); GOTOERROR(FAIL); } @@ -404,10 +401,10 @@ sio_create_filename(iotype iot, const char *base_name, char *fullname, size_t si /* Remove any double slashes in the filename */ for (ptr = fullname, i = j = 0; ptr && (i < size); i++, ptr++) { - if (*ptr != '/' || last != '/') - fullname[j++] = *ptr; + if (*ptr != '/' || last != '/') + fullname[j++] = *ptr; - last = *ptr; + last = *ptr; } return fullname; @@ -766,6 +763,7 @@ done: static herr_t do_read(results *res, file_descr *fd, parameters *parms, void *buffer) { + char *buffer2 = NULL; /* Buffer for data verification */ int ret_code = SUCCESS; char dname[64]; long i; @@ -777,14 +775,19 @@ do_read(results *res, file_descr *fd, parameters *parms, void *buffer) hsize_t h5start[MAX_DIMS]; /*selection start */ int rank; - /* Prepare buffer for verifying data */ - for (i=0; i < linear_buf_size; i++) - buffer2[i]=i%128; + /* Allocate data verification buffer */ + if(NULL == (buffer2 = (char *)malloc(linear_buf_size))) { + HDfprintf(stderr, "malloc for data verification buffer size (%Zu) failed\n", linear_buf_size); + GOTOERROR(FAIL); + } /* end if */ + + /* Prepare buffer for verifying data */ + for(i = 0; i < linear_buf_size; i++) + buffer2[i] = i % 128; rank = parms->rank; - for (i=0; i<rank; i++) { + for(i = 0; i < rank; i++) h5offset[i] = offset[i] = 0; - } /* I/O Access specific setup */ switch (parms->io_type) { @@ -853,7 +856,7 @@ do_read(results *res, file_descr *fd, parameters *parms, void *buffer) /* Start "raw data" read timer */ set_time(res->timers, HDF5_RAW_READ_FIXED_DIMS, START); - hrc = dset_read(rank-1, fd, parms, buffer); + hrc = dset_read(rank-1, fd, parms, buffer, buffer2); if (hrc < 0) { fprintf(stderr, "Error in dataset read\n"); @@ -910,6 +913,10 @@ done: } } + /* release generic resources */ + if(buffer2) + free(buffer2); + return ret_code; } @@ -921,7 +928,8 @@ done: * Modifications: */ -static herr_t dset_read(int local_dim, file_descr *fd, parameters *parms, void *buffer) +static herr_t dset_read(int local_dim, file_descr *fd, parameters *parms, + void *buffer, const char *buffer2) { int cur_dim = order[local_dim]-1; int ret_code = SUCCESS; @@ -936,7 +944,7 @@ static herr_t dset_read(int local_dim, file_descr *fd, parameters *parms, void * /* if traverse in order array is incomplete, recurse */ if (local_dim > 0){ - ret_code = dset_read(local_dim-1, fd, parms, buffer); + ret_code = dset_read(local_dim-1, fd, parms, buffer, buffer2); /* otherwise, write buffer into dataset */ }else{ |