summaryrefslogtreecommitdiffstats
path: root/hl
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2010-01-23 07:00:00 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2010-01-23 07:00:00 (GMT)
commitbb25c85e794449d3bf59d8811e53288569161790 (patch)
treee6c37cf6f8bba9323540ddddb70300b43351d88f /hl
parentfcc03a356b4dd5e58cc88b692b3d05d75b8ae5d0 (diff)
downloadhdf5-bb25c85e794449d3bf59d8811e53288569161790.zip
hdf5-bb25c85e794449d3bf59d8811e53288569161790.tar.gz
hdf5-bb25c85e794449d3bf59d8811e53288569161790.tar.bz2
[svn-r18159] Description:
Bring Coverity fixes from 1/22/10 session to trunk: r18137: 219: Initialized hid_t to -1 and added close to error block. 189-191: Initialized line to NULL and added free line, and close fp to error block. r18138: 19: Moved code block for printing that the number of enums is empty to the error block. (Would never have been executed otherwise) r18139: Fix coverity item 58. Moved code related to displaying the parent of a repeated group to the else(isRoot) section, as the root group has no parent. r18140: 218: Initialized ret_value variable to -1. Because of throw Exception in default case of switch, the coverity problem would not have executed anyway. Good pratice is to initialize variables. r18141: Fix coverity item 92. Added code to H5E_register_class to free cls in case of an error. r18142: Fix coverity item 91. Added code to H5E_create_msg to free msg in case of an error. r18143: fixed issue 14, took away "if" and used #ifndef_xxx. r18144: Fix coverity item 110. Added code to H5Eget_minor to free msg_str in case of an error. r18145: fixed coverity #18 removed "aligned", it is always NULL. r18146: Fix coverity item 109. Added code to H5Eget_major to free msg_str in case of an error. r18147: Fixed coverity #81 and #82, Check for bad pointer(s), but can't issue error, just leave r18148: Fix coverity item 97. Added code to H5FD_fapl_open to free copied_driver_info in case of an error. r18149: Fix coverity item 96. Added code to H5FD_dxpl_open to free copied_driver_info in case of an error. r18150: Fix Coverity issue #29: Protected cache_ptr dereferences with "if(pass)" block r18151: Fix coverity item 93. Added code to H5FL_fac_init to free factory and new_node in case of an error. r18152: Fix coverity items 98 and 99. Added code free allocated space in case of error. r18155: 124: Freed head pointer before jumping to done. There was no error handling block and normal exit used same path out. 120-123: Freed list of lists in error handling block. r18156: Fix coverity issues 179, 180, 181, 182, 183, 184, 186, 320, 407. These were resource leak issues where allocated memory was not freed, generally in the case of tests that failed. Tested on: Mac OS X/32 10.6.2 (amazon) debug & production
Diffstat (limited to 'hl')
-rw-r--r--hl/src/H5LT.c9
-rw-r--r--hl/src/H5TB.c63
-rw-r--r--hl/test/test_lite.c19
3 files changed, 40 insertions, 51 deletions
diff --git a/hl/src/H5LT.c b/hl/src/H5LT.c
index c38d383..d118942 100644
--- a/hl/src/H5LT.c
+++ b/hl/src/H5LT.c
@@ -1749,14 +1749,15 @@ print_enum(hid_t type, char* str, int indt)
free(value);
H5Tclose(super);
+ return ret;
+
+out:
+
if(0 == nmembs) {
sprintf(tmp_str, "\n%*s <empty>", indt + 4, "");
strcat(str, tmp_str);
} /* end if */
-
- return ret;
-
-out:
+
/* Release resources */
if(name) {
for(i = 0; i < nmembs; i++)
diff --git a/hl/src/H5TB.c b/hl/src/H5TB.c
index a035319..b9cb73c 100644
--- a/hl/src/H5TB.c
+++ b/hl/src/H5TB.c
@@ -3213,16 +3213,12 @@ herr_t H5TBget_field_info( hid_t loc_id,
size_t *field_offsets,
size_t *type_size )
{
- hid_t did; /* dataset ID */
- hid_t tid; /* file type ID */
- hid_t n_tid; /* native type ID */
- hid_t m_tid; /* member type ID */
- hid_t nm_tid; /* native member ID */
+ hid_t did = -1; /* dataset ID */
+ hid_t tid = -1; /* file type ID */
+ hid_t n_tid = -1; /* native type ID */
+ hid_t m_tid = -1; /* member type ID */
+ hid_t nm_tid = -1; /* native member ID */
hssize_t nfields;
- char *member_name;
- size_t member_size;
- size_t member_offset;
- size_t size;
hssize_t i;
/* open the dataset. */
@@ -3233,62 +3229,47 @@ herr_t H5TBget_field_info( hid_t loc_id,
if (( tid = H5Dget_type( did )) < 0)
goto out;
- if ((n_tid = H5Tget_native_type(tid,H5T_DIR_DEFAULT)) < 0)
+ if ((n_tid = H5Tget_native_type(tid, H5T_DIR_DEFAULT)) < 0)
goto out;
/* get the type size */
- size = H5Tget_size( n_tid );
-
- if ( type_size )
- {
- *type_size = size;
- }
+ if(type_size)
+ *type_size = H5Tget_size(n_tid);
/* get the number of members */
if (( nfields = H5Tget_nmembers( tid )) < 0)
goto out;
/* iterate tru the members */
- for ( i = 0; i < nfields; i++)
- {
+ for ( i = 0; i < nfields; i++) {
/* get the member name */
- member_name = H5Tget_member_name( tid, (unsigned)i );
+ if(field_names) {
+ char *member_name;
- if (field_names )
- {
- strcpy( field_names[i], member_name );
- }
+ member_name = H5Tget_member_name(tid, (unsigned)i);
+ strcpy(field_names[i], member_name);
+ free(member_name);
+ } /* end if */
/* get the member type */
- if (( m_tid = H5Tget_member_type( tid,(unsigned) i )) < 0)
+ if(( m_tid = H5Tget_member_type( tid,(unsigned) i )) < 0)
goto out;
- if ((nm_tid = H5Tget_native_type(m_tid,H5T_DIR_DEFAULT)) < 0)
+ if((nm_tid = H5Tget_native_type(m_tid,H5T_DIR_DEFAULT)) < 0)
goto out;
/* get the member size */
- member_size = H5Tget_size( nm_tid );
-
- if(field_sizes )
- {
- field_sizes[i] = member_size;
- }
+ if(field_sizes)
+ field_sizes[i] = H5Tget_size(nm_tid);
/* get the member offset */
- member_offset = H5Tget_member_offset( n_tid,(unsigned) i );
-
- if(field_offsets )
- {
- field_offsets[i] = member_offset;
- }
+ if(field_offsets)
+ field_offsets[i] = H5Tget_member_offset(n_tid, (unsigned) i);
/* close the member types */
if (H5Tclose( m_tid ) < 0)
goto out;
if (H5Tclose( nm_tid ) < 0)
goto out;
-
- free( member_name );
-
} /* i */
/* close */
@@ -3308,6 +3289,8 @@ out:
H5Dclose(did);
H5Tclose(tid);
H5Tclose(n_tid);
+ H5Tclose(m_tid);
+ H5Tclose(nm_tid);
} H5E_END_TRY;
return -1;
diff --git a/hl/test/test_lite.c b/hl/test/test_lite.c
index ad12fb2..9234344 100644
--- a/hl/test/test_lite.c
+++ b/hl/test/test_lite.c
@@ -1535,17 +1535,16 @@ static int test_complicated_compound(void)
hid_t dtype;
int nmembs;
H5T_class_t type_class;
- char* line=NULL;
- FILE *fp;
+ char *line = NULL;
+ FILE *fp = NULL;
size_t size = 1024;
- char *srcdir = getenv("srcdir"); /* the source directory */
+ char *srcdir = getenv("srcdir"); /* the source directory */
char filename[1024]="";
TESTING3(" text for complicated compound types");
/* compose the name of the file to open, using the srcdir, if appropriate */
- if(srcdir)
- {
+ if(srcdir) {
strcpy(filename, srcdir);
strcat(filename, "/");
}
@@ -1553,8 +1552,7 @@ static int test_complicated_compound(void)
/* Open input file */
fp = fopen(filename, "r");
- if(fp == NULL)
- {
+ if(fp == NULL) {
printf( "Could not find file %s. Try set $srcdir \n", filename);
goto out;
}
@@ -1580,6 +1578,7 @@ static int test_complicated_compound(void)
}
fclose(fp);
+ fp = NULL;
if((dtype = H5LTtext_to_dtype(line, H5LT_DDL))<0)
goto out;
@@ -1602,6 +1601,12 @@ static int test_complicated_compound(void)
return 0;
out:
+
+ if(line)
+ free(line);
+ if(fp)
+ fclose(fp);
+
H5_FAILED();
return -1;
}