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/iopipe.c | |
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/iopipe.c')
-rw-r--r-- | perform/iopipe.c | 126 |
1 files changed, 60 insertions, 66 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; } + |