summaryrefslogtreecommitdiffstats
path: root/src/H5FDlog.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2009-12-13 12:50:01 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2009-12-13 12:50:01 (GMT)
commit6c9d003d4ee3bbcaf639149014e8e42ed9835621 (patch)
tree95169b1d25c154882a92b1c68d65c4bc65b04cc9 /src/H5FDlog.c
parent7f46301cee98932ecf7ad87068adc0f5d051d544 (diff)
downloadhdf5-6c9d003d4ee3bbcaf639149014e8e42ed9835621.zip
hdf5-6c9d003d4ee3bbcaf639149014e8e42ed9835621.tar.gz
hdf5-6c9d003d4ee3bbcaf639149014e8e42ed9835621.tar.bz2
[svn-r18013] Description:
Bring r18011 from trunk to 1.8 branch: Bring Coverity changes into the trunk: (also other minor cleanups) r17991: Fix Coverity items 175 and 176. Fixed memory leak on error in print_enum in H5LT.c. r17993: (r17992 was not a Coverity change) Close Coverity issue #206: inconsistently checking whether dt->shared was non-NULL after H5T_alloc() returned a valid 'dt' value (which should guarantee that dt->shared is valid). r17994: Fix Coverity item 149. Fixed file handle leak on error in H5FD_stdio_open. r17995: Fixed Coverity issues 154 to 161: Added H5MP_close routine to error handling in the event *mp has not been freed before error. r17996: Close Coverity issue #126: potentially leaking merged_spans on routine failure. r17997: Fix Coverity items 147 and 148. Fixed resource leaks on error in H5FDloc.c. r17998: Coverity issue 269-272: Added integer result variable to functions that could return negative. Assigned to unsigned after checking. Added H5E_BEGIN_TRY block around H5Tclose and removed H5E_THROW in the catch block. Checked buffer is NULL before free. Changed HGOTO_ERROR outside of the if block to H5E_THROW. r17999: Close Coverity issue #127: release temporary spans in more generic manner. (Also add error checking to previous fix) r18000: Resolved Coverity issues 211 and 212 in H5T.c. Added comments to ignore Coverity warning regarding not checking pointer for NULL, as we are using an assert which catches the issue. r18001: Fix Coverity item 146. Fixed resource leak on error in H5O_layout_copy. r18002: Fix Coverity items 143 and 145. Fixed resource leaks on error in H5D_compact_copy and H5D_contig_copy. r18003: Close Coverity issue #192: close file on error r18004: Fix Coverity issue #125: release temporary spans on error r18005: Resolved Coverity issues 5, 25, and 83 (in H5T.c): Separated embedded functions in order to check for NULL on return of H5I_object before passing into H5T_copy. Check to see if new_dt is NULL within error handling before dereferencing it. Ignore Coverity's dead code warnings as the checks that lead to the code are machine dependent. r18006: Coverity 63,70,73: Checked result of function before assigning to an unsigned variable. r18007: Coverity 78,79: added continue statement if H5Pget_filter2 returns negative. r18008: Fixed Coverity issue # 138: Added support in error handling to free dst pointer (if allocated) on error. r18009: Whitespace & coding style cleanup Tested on: Mac OS X/32 10.6.2 (amazon) w/debug & production (h5committested on trunk)
Diffstat (limited to 'src/H5FDlog.c')
-rw-r--r--src/H5FDlog.c151
1 files changed, 77 insertions, 74 deletions
diff --git a/src/H5FDlog.c b/src/H5FDlog.c
index 051195e..bde63cc 100644
--- a/src/H5FDlog.c
+++ b/src/H5FDlog.c
@@ -409,39 +409,47 @@ done:
* Purpose: Copies the log-specific file access properties.
*
* Return: Success: Ptr to a new property list
- *
* Failure: NULL
*
* Programmer: Quincey Koziol
* Thursday, April 20, 2000
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static void *
H5FD_log_fapl_copy(const void *_old_fa)
{
const H5FD_log_fapl_t *old_fa = (const H5FD_log_fapl_t*)_old_fa;
- H5FD_log_fapl_t *new_fa = (H5FD_log_fapl_t *)H5MM_malloc(sizeof(H5FD_log_fapl_t));
+ H5FD_log_fapl_t *new_fa = NULL; /* New FAPL info */
void *ret_value; /* Return value */
FUNC_ENTER_NOAPI(H5FD_log_fapl_copy, NULL)
HDassert(new_fa);
+ /* Allocate the new FAPL info */
+ if(NULL == (new_fa = (H5FD_log_fapl_t *)H5MM_calloc(sizeof(H5FD_log_fapl_t))))
+ HGOTO_ERROR(H5E_FILE, H5E_CANTALLOC, NULL, "unable to allocate log file FAPL")
+
/* Copy the general information */
HDmemcpy(new_fa, old_fa, sizeof(H5FD_log_fapl_t));
/* Deep copy the log file name */
- if(old_fa->logfile!=NULL)
- if (NULL==(new_fa->logfile=H5MM_xstrdup(old_fa->logfile)))
+ if(old_fa->logfile != NULL)
+ if(NULL == (new_fa->logfile = H5MM_xstrdup(old_fa->logfile)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate log file name")
/* Set return value */
- ret_value=new_fa;
+ ret_value = new_fa;
done:
+ if(NULL == ret_value)
+ if(new_fa) {
+ if(new_fa->logfile)
+ H5MM_free(new_fa->logfile);
+ H5MM_free(new_fa);
+ } /* end if */
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_log_fapl_copy() */
@@ -452,21 +460,18 @@ done:
* Purpose: Frees the log-specific file access properties.
*
* Return: Success: 0
- *
* Failure: -1
*
* Programmer: Quincey Koziol
* Thursday, April 20, 2000
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static herr_t
H5FD_log_fapl_free(void *_fa)
{
H5FD_log_fapl_t *fa = (H5FD_log_fapl_t*)_fa;
- herr_t ret_value=SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5FD_log_fapl_free, FAIL)
@@ -488,52 +493,52 @@ done:
* Return: Success: A pointer to a new file data structure. The
* public fields will be initialized by the
* caller, which is always H5FD_open().
- *
* Failure: NULL
*
* Programmer: Robb Matzke
* Thursday, July 29, 1999
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static H5FD_t *
H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id,
haddr_t maxaddr)
{
- int o_flags;
- int fd=(-1);
- H5FD_log_t *file=NULL;
+ int o_flags;
+ int fd = (-1);
+ H5FD_log_t *file = NULL;
H5FD_log_fapl_t *fa; /* File access property list information */
#ifdef _WIN32
HFILE filehandle;
struct _BY_HANDLE_FILE_INFORMATION fileinfo;
#endif
- h5_stat_t sb;
+ h5_stat_t sb;
H5P_genplist_t *plist; /* Property list */
H5FD_t *ret_value;
FUNC_ENTER_NOAPI(H5FD_log_open, NULL)
/* Check arguments */
- if (!name || !*name)
+ if(!name || !*name)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid file name")
- if (0==maxaddr || HADDR_UNDEF==maxaddr)
+ if(0 == maxaddr || HADDR_UNDEF == maxaddr)
HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL, "bogus maxaddr")
- if (ADDR_OVERFLOW(maxaddr))
+ if(ADDR_OVERFLOW(maxaddr))
HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "bogus maxaddr")
/* Build the open flags */
o_flags = (H5F_ACC_RDWR & flags) ? O_RDWR : O_RDONLY;
- if (H5F_ACC_TRUNC & flags) o_flags |= O_TRUNC;
- if (H5F_ACC_CREAT & flags) o_flags |= O_CREAT;
- if (H5F_ACC_EXCL & flags) o_flags |= O_EXCL;
+ if(H5F_ACC_TRUNC & flags)
+ o_flags |= O_TRUNC;
+ if(H5F_ACC_CREAT & flags)
+ o_flags |= O_CREAT;
+ if(H5F_ACC_EXCL & flags)
+ o_flags |= O_EXCL;
/* Open the file */
- if ((fd=HDopen(name, o_flags, 0666))<0)
+ if((fd = HDopen(name, o_flags, 0666)) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file")
- if (HDfstat(fd, &sb)<0)
+ if(HDfstat(fd, &sb) < 0)
HGOTO_ERROR(H5E_FILE, H5E_BADFILE, NULL, "unable to fstat file")
/* Create the new file struct */
@@ -541,7 +546,7 @@ H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id,
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate file struct")
/* Get the driver specific information */
- if(NULL == (plist = H5P_object_verify(fapl_id,H5P_FILE_ACCESS)))
+ if(NULL == (plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list")
fa = (H5FD_log_fapl_t *)H5P_get_driver_info(plist);
HDassert(fa);
@@ -561,7 +566,7 @@ H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id,
#endif
/* Get the flags for logging */
- file->fa.flags=fa->flags;
+ file->fa.flags = fa->flags;
/* Check if we are doing any logging at all */
if(file->fa.flags != 0) {
@@ -591,6 +596,7 @@ done:
if(NULL == ret_value) {
if(fd >= 0)
HDclose(fd);
+ file = (H5FD_log_t *)H5MM_xfree(file);
} /* end if */
FUNC_LEAVE_NOAPI(ret_value)
@@ -603,14 +609,11 @@ done:
* Purpose: Closes a Unix file.
*
* Return: Success: 0
- *
* Failure: -1, file not closed.
*
* Programmer: Robb Matzke
* Thursday, July 29, 1999
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static herr_t
@@ -621,7 +624,7 @@ H5FD_log_close(H5FD_t *_file)
struct timeval timeval_start,timeval_stop;
struct timeval timeval_diff;
#endif /* H5_HAVE_GETTIMEOFDAY */
- herr_t ret_value=SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5FD_log_close, FAIL)
@@ -629,7 +632,7 @@ H5FD_log_close(H5FD_t *_file)
if(file->fa.flags&H5FD_LOG_TIME_CLOSE)
HDgettimeofday(&timeval_start,NULL);
#endif /* H5_HAVE_GETTIMEOFDAY */
- if (HDclose(file->fd)<0)
+ if(HDclose(file->fd) < 0)
HGOTO_ERROR(H5E_IO, H5E_CANTCLOSEFILE, FAIL, "unable to close file")
#ifdef H5_HAVE_GETTIMEOFDAY
if(file->fa.flags&H5FD_LOG_TIME_CLOSE)
@@ -637,73 +640,73 @@ H5FD_log_close(H5FD_t *_file)
#endif /* H5_HAVE_GETTIMEOFDAY */
/* Dump I/O information */
- if(file->fa.flags!=0) {
+ if(file->fa.flags != 0) {
haddr_t addr;
haddr_t last_addr;
unsigned char last_val;
#ifdef H5_HAVE_GETTIMEOFDAY
- if(file->fa.flags&H5FD_LOG_TIME_CLOSE) {
+ if(file->fa.flags & H5FD_LOG_TIME_CLOSE) {
/* Calculate the elapsed gettimeofday time */
- timeval_diff.tv_usec=timeval_stop.tv_usec-timeval_start.tv_usec;
- timeval_diff.tv_sec=timeval_stop.tv_sec-timeval_start.tv_sec;
- if(timeval_diff.tv_usec<0) {
- timeval_diff.tv_usec+=1000000;
+ timeval_diff.tv_usec = timeval_stop.tv_usec - timeval_start.tv_usec;
+ timeval_diff.tv_sec = timeval_stop.tv_sec - timeval_start.tv_sec;
+ if(timeval_diff.tv_usec < 0) {
+ timeval_diff.tv_usec += 1000000;
timeval_diff.tv_sec--;
} /* end if */
- HDfprintf(file->logfp,"Close took: (%f s)\n",(double)timeval_diff.tv_sec+((double)timeval_diff.tv_usec/(double)1000000.0));
+ HDfprintf(file->logfp, "Close took: (%f s)\n", (double)timeval_diff.tv_sec + ((double)timeval_diff.tv_usec / (double)1000000.0));
} /* end if */
#endif /* H5_HAVE_GETTIMEOFDAY */
/* Dump the write I/O information */
- if(file->fa.flags&H5FD_LOG_FILE_WRITE) {
- HDfprintf(file->logfp,"Dumping write I/O information:\n");
- last_val=file->nwrite[0];
- last_addr=0;
- addr=1;
- while(addr<file->eoa) {
- if(file->nwrite[addr]!=last_val) {
- HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) written to %3d times\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),(int)last_val);
- last_val=file->nwrite[addr];
- last_addr=addr;
+ if(file->fa.flags & H5FD_LOG_FILE_WRITE) {
+ HDfprintf(file->logfp, "Dumping write I/O information:\n");
+ last_val = file->nwrite[0];
+ last_addr = 0;
+ addr = 1;
+ while(addr < file->eoa) {
+ if(file->nwrite[addr] != last_val) {
+ HDfprintf(file->logfp, "\tAddr %10a-%10a (%10lu bytes) written to %3d times\n", last_addr, (addr - 1), (unsigned long)(addr - last_addr), (int)last_val);
+ last_val = file->nwrite[addr];
+ last_addr = addr;
} /* end if */
addr++;
} /* end while */
- HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) written to %3d times\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),(int)last_val);
+ HDfprintf(file->logfp, "\tAddr %10a-%10a (%10lu bytes) written to %3d times\n", last_addr, (addr - 1), (unsigned long)(addr - last_addr), (int)last_val);
} /* end if */
/* Dump the read I/O information */
- if(file->fa.flags&H5FD_LOG_FILE_READ) {
- HDfprintf(file->logfp,"Dumping read I/O information:\n");
- last_val=file->nread[0];
- last_addr=0;
- addr=1;
- while(addr<file->eoa) {
- if(file->nread[addr]!=last_val) {
- HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) read from %3d times\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),(int)last_val);
- last_val=file->nread[addr];
- last_addr=addr;
+ if(file->fa.flags & H5FD_LOG_FILE_READ) {
+ HDfprintf(file->logfp, "Dumping read I/O information:\n");
+ last_val = file->nread[0];
+ last_addr = 0;
+ addr = 1;
+ while(addr < file->eoa) {
+ if(file->nread[addr] != last_val) {
+ HDfprintf(file->logfp, "\tAddr %10a-%10a (%10lu bytes) read from %3d times\n", last_addr, (addr - 1), (unsigned long)(addr - last_addr), (int)last_val);
+ last_val = file->nread[addr];
+ last_addr = addr;
} /* end if */
addr++;
} /* end while */
- HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) read from %3d times\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),(int)last_val);
+ HDfprintf(file->logfp, "\tAddr %10a-%10a (%10lu bytes) read from %3d times\n", last_addr, (addr - 1), (unsigned long)(addr - last_addr), (int)last_val);
} /* end if */
/* Dump the I/O flavor information */
- if(file->fa.flags&H5FD_LOG_FLAVOR) {
- HDfprintf(file->logfp,"Dumping I/O flavor information:\n");
- last_val=file->flavor[0];
- last_addr=0;
- addr=1;
- while(addr<file->eoa) {
- if(file->flavor[addr]!=last_val) {
- HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) flavor is %s\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),flavors[last_val]);
- last_val=file->flavor[addr];
- last_addr=addr;
+ if(file->fa.flags & H5FD_LOG_FLAVOR) {
+ HDfprintf(file->logfp, "Dumping I/O flavor information:\n");
+ last_val = file->flavor[0];
+ last_addr = 0;
+ addr = 1;
+ while(addr < file->eoa) {
+ if(file->flavor[addr] != last_val) {
+ HDfprintf(file->logfp, "\tAddr %10a-%10a (%10lu bytes) flavor is %s\n", last_addr, (addr - 1), (unsigned long)(addr - last_addr), flavors[last_val]);
+ last_val = file->flavor[addr];
+ last_addr = addr;
} /* end if */
addr++;
} /* end while */
- HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) flavor is %s\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),flavors[last_val]);
+ HDfprintf(file->logfp, "\tAddr %10a-%10a (%10lu bytes) flavor is %s\n", last_addr, (addr - 1), (unsigned long)(addr - last_addr), flavors[last_val]);
} /* end if */
/* Free the logging information */
@@ -721,7 +724,7 @@ H5FD_log_close(H5FD_t *_file)
done:
FUNC_LEAVE_NOAPI(ret_value)
-}
+} /* end H5FD_log_close() */
/*-------------------------------------------------------------------------