summaryrefslogtreecommitdiffstats
path: root/c++/test
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2011-02-06 03:24:42 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2011-02-06 03:24:42 (GMT)
commitff845ed8b156097fd8574be4809f11dbc684e042 (patch)
treef564359ab09ae660be620733d4144f6b78ac7ce5 /c++/test
parent299ac26d98a27cb309c87eafeb0ff7ac53eeb94b (diff)
downloadhdf5-ff845ed8b156097fd8574be4809f11dbc684e042.zip
hdf5-ff845ed8b156097fd8574be4809f11dbc684e042.tar.gz
hdf5-ff845ed8b156097fd8574be4809f11dbc684e042.tar.bz2
[svn-r20052] Description:
Clean up Coverity warnings, and fix some style issues: r19735: Fix for memory leak in test/mf found by valgrind. r19736: Fix memory leak in h5repack. The buffer in copy_objects, when copying the entire dataset at once, was not checked for the presence of a vlen, and vlen storage was never reclaimed. Added check and call to H5D_vlen_reclaim(). r19772: Change H5assert() to if (H5T_VLEN != src->shared->type || H5T_VLEN != dst->shared->type) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a H5T_VLEN datatype") r19774: removed unused priv. r19775: removed unused variables r19778: Fix memory leak comparing for variable length data types. r19834: Fixed memory leaks found by valgrind. Memory errors remain for another day. Tested on: Mac OS X/32 10.6.6 (amazon) w/debug & production (h5committested on branch)
Diffstat (limited to 'c++/test')
-rw-r--r--c++/test/tcompound.cpp34
-rw-r--r--c++/test/tfilter.cpp87
-rw-r--r--c++/test/tlinks.cpp1
-rw-r--r--c++/test/trefer.cpp3
-rw-r--r--c++/test/ttypes.cpp8
-rw-r--r--c++/test/tvlstr.cpp28
6 files changed, 102 insertions, 59 deletions
diff --git a/c++/test/tcompound.cpp b/c++/test/tcompound.cpp
index fb8bd17..fbb1219 100644
--- a/c++/test/tcompound.cpp
+++ b/c++/test/tcompound.cpp
@@ -115,7 +115,8 @@ static void test_compound_2()
const int nelmts = NTESTELEM;
const hsize_t four = 4;
int i;
- unsigned char *buf=NULL, *orig=NULL, *bkg=NULL;
+ unsigned char *buf = NULL, *orig = NULL, *bkg = NULL;
+ ArrayType *array_dt = NULL;
// Output message about test being performed
SUBTEST("Compound Element Reordering");
@@ -138,7 +139,7 @@ static void test_compound_2()
memcpy(buf, orig, nelmts*sizeof(src_typ_t));
// Build hdf5 datatypes
- ArrayType* array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four);
+ array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four);
// Create an empty compound datatype
CompType st(sizeof(src_typ_t));
@@ -148,6 +149,7 @@ static void test_compound_2()
st.insertMember("d", HOFFSET(src_typ_t, d), PredType::NATIVE_INT);
st.insertMember("e", HOFFSET(src_typ_t, e), PredType::NATIVE_INT);
array_dt->close();
+ delete array_dt;
array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four);
@@ -202,6 +204,9 @@ static void test_compound_2()
cerr << "test_compound_2 in catch" << endl;
issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg());
}
+
+ if(array_dt)
+ delete array_dt;
} // test_compound_2()
@@ -235,7 +240,8 @@ static void test_compound_3()
int i;
const int nelmts = NTESTELEM;
const hsize_t four = 4;
- unsigned char *buf=NULL, *orig=NULL, *bkg=NULL;
+ unsigned char *buf = NULL, *orig = NULL, *bkg = NULL;
+ ArrayType* array_dt = NULL;
// Output message about test being performed
SUBTEST("Compound Datatype Subset Conversions");
@@ -258,7 +264,7 @@ static void test_compound_3()
memcpy(buf, orig, nelmts*sizeof(src_typ_t));
/* Build hdf5 datatypes */
- ArrayType* array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four);
+ array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four);
// Create an empty compound datatype
CompType st(sizeof(src_typ_t));
@@ -268,6 +274,7 @@ static void test_compound_3()
st.insertMember("d", HOFFSET(src_typ_t, d), PredType::NATIVE_INT);
st.insertMember("e", HOFFSET(src_typ_t, e), PredType::NATIVE_INT);
array_dt->close();
+ delete array_dt;
array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four);
@@ -319,6 +326,9 @@ static void test_compound_3()
cerr << "test_compound_3 in catch" << endl;
issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg());
}
+
+ if(array_dt)
+ delete array_dt;
} // test_compound_3()
@@ -357,7 +367,8 @@ static void test_compound_4()
int i;
const int nelmts = NTESTELEM;
const hsize_t four = 4;
- unsigned char *buf=NULL, *orig=NULL, *bkg=NULL;
+ unsigned char *buf = NULL, *orig = NULL, *bkg = NULL;
+ ArrayType* array_dt = NULL;
// Output message about test being performed
SUBTEST("Compound Element Shrinking & Reordering");
@@ -380,7 +391,7 @@ static void test_compound_4()
memcpy(buf, orig, nelmts*sizeof(src_typ_t));
/* Build hdf5 datatypes */
- ArrayType* array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four);
+ array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four);
// Create an empty compound datatype
CompType st(sizeof(src_typ_t));
@@ -390,6 +401,7 @@ static void test_compound_4()
st.insertMember("d", HOFFSET(src_typ_t, d), PredType::NATIVE_INT);
st.insertMember("e", HOFFSET(src_typ_t, e), PredType::NATIVE_INT);
array_dt->close();
+ delete array_dt;
array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four);
@@ -446,6 +458,9 @@ static void test_compound_4()
cerr << "test_compound_4 in catch" << endl;
issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg());
}
+
+ if(array_dt)
+ delete array_dt;
} // test_compound_4()
@@ -486,16 +501,18 @@ static void test_compound_5()
dst_typ_t *dst;
void *buf = calloc(2, sizeof(dst_typ_t));
void *bkg = calloc(2, sizeof(dst_typ_t));
+ ArrayType* array_dt = NULL;
// Output message about test being performed
SUBTEST("Optimized Struct Converter");
try {
/* Build datatypes */
- ArrayType* array_dt = new ArrayType(PredType::NATIVE_SHORT, 1, dims);
+ array_dt = new ArrayType(PredType::NATIVE_SHORT, 1, dims);
CompType short_array(4*sizeof(short));
short_array.insertMember("_", 0, *array_dt);
array_dt->close();
+ delete array_dt;
CompType int_array(4*sizeof(int));
array_dt = new ArrayType(PredType::NATIVE_INT, 1, dims);
@@ -545,6 +562,9 @@ static void test_compound_5()
cerr << "test_compound_5 in catch" << endl;
issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg());
}
+
+ if(array_dt)
+ delete array_dt;
} // test_compound_5()
diff --git a/c++/test/tfilter.cpp b/c++/test/tfilter.cpp
index e59707a..0dbdf00 100644
--- a/c++/test/tfilter.cpp
+++ b/c++/test/tfilter.cpp
@@ -174,58 +174,61 @@ void test_szip_filter(H5File& file1)
SUBTEST("szip filter (with encoder)");
if ( h5_szip_can_encode() == 1) {
- char* tconv_buf = new char [1000];
- try {
- const hsize_t size[2] = {DSET_DIM1, DSET_DIM2};
-
- // Create the data space
- DataSpace space1(2, size, NULL);
+ char* tconv_buf = new char [1000];
- // Create a small conversion buffer to test strip mining (?)
- DSetMemXferPropList xfer;
- xfer.setBuffer (1000, tconv_buf, NULL);
+ try {
+ const hsize_t size[2] = {DSET_DIM1, DSET_DIM2};
- // Prepare dataset create property list
- DSetCreatPropList dsplist;
- dsplist.setChunk(2, chunk_size);
+ // Create the data space
+ DataSpace space1(2, size, NULL);
- // Set up for szip compression
- dsplist.setSzip(szip_options_mask, szip_pixels_per_block);
+ // Create a small conversion buffer to test strip mining (?)
+ DSetMemXferPropList xfer;
+ xfer.setBuffer (1000, tconv_buf, NULL);
- // Create a dataset with szip compression
- DataSpace space2 (2, size, NULL);
- DataSet dataset(file1.createDataSet (DSET_SZIP_NAME, PredType::NATIVE_INT, space2, dsplist));
+ // Prepare dataset create property list
+ DSetCreatPropList dsplist;
+ dsplist.setChunk(2, chunk_size);
- hsize_t i, j, n;
- for (i=n=0; i<size[0]; i++)
- {
- for (j=0; j<size[1]; j++)
- {
- points[i][j] = (int)n++;
- }
- }
+ // Set up for szip compression
+ dsplist.setSzip(szip_options_mask, szip_pixels_per_block);
- // Write to the dataset then read back the values
- dataset.write ((void*)points, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
- dataset.read ((void*)check, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
+ // Create a dataset with szip compression
+ DataSpace space2 (2, size, NULL);
+ DataSet dataset(file1.createDataSet (DSET_SZIP_NAME, PredType::NATIVE_INT, space2, dsplist));
- // Check that the values read are the same as the values written
- for (i = 0; i < size[0]; i++)
- for (j = 0; j < size[1]; j++)
+ hsize_t i, j, n;
+ for (i=n=0; i<size[0]; i++)
{
- int status = check_values (i, j, points[i][j], check[i][j]);
- if (status == -1)
- throw Exception("test_szip_filter", "Failed in testing szip method");
+ for (j=0; j<size[1]; j++)
+ {
+ points[i][j] = (int)n++;
+ }
}
- dsplist.close();
- PASSED();
- } // end of try
- // catch all other exceptions
- catch (Exception E)
- {
- issue_fail_msg("test_szip_filter()", __LINE__, __FILE__, E.getCDetailMsg());
- }
+ // Write to the dataset then read back the values
+ dataset.write ((void*)points, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
+ dataset.read ((void*)check, PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer);
+
+ // Check that the values read are the same as the values written
+ for (i = 0; i < size[0]; i++)
+ for (j = 0; j < size[1]; j++)
+ {
+ int status = check_values (i, j, points[i][j], check[i][j]);
+ if (status == -1)
+ throw Exception("test_szip_filter", "Failed in testing szip method");
+ }
+ dsplist.close();
+ PASSED();
+ } // end of try
+
+ // catch all other exceptions
+ catch (Exception E)
+ {
+ issue_fail_msg("test_szip_filter()", __LINE__, __FILE__, E.getCDetailMsg());
+ }
+
+ delete tconv_buf;
} // if szip presents
else {
SKIPPED();
diff --git a/c++/test/tlinks.cpp b/c++/test/tlinks.cpp
index 53a1c8c..e4e691a 100644
--- a/c++/test/tlinks.cpp
+++ b/c++/test/tlinks.cpp
@@ -403,7 +403,6 @@ static void test_basic_links(hid_t fapl_id, hbool_t new_format)
{
hsize_t size[1] = {1};
char filename[NAME_BUF_SIZE];
- char* tconv_buf = new char [1000];
// Use the file access template id to create a file access prop. list.
FileAccPropList fapl(fapl_id);
diff --git a/c++/test/trefer.cpp b/c++/test/trefer.cpp
index aeb202a..7f63d33 100644
--- a/c++/test/trefer.cpp
+++ b/c++/test/trefer.cpp
@@ -326,6 +326,9 @@ static void test_reference_obj(void)
catch (Exception E) {
issue_fail_msg("test_reference_obj()", __LINE__, __FILE__, E.getCDetailMsg());
}
+
+ if(file1)
+ delete file1;
} // test_reference_obj()
/****************************************************************
diff --git a/c++/test/ttypes.cpp b/c++/test/ttypes.cpp
index ef00c08..b1baa29 100644
--- a/c++/test/ttypes.cpp
+++ b/c++/test/ttypes.cpp
@@ -387,6 +387,7 @@ static void test_named ()
static hsize_t ds_size[2] = {10, 20};
hsize_t i;
unsigned attr_data[10][20];
+ DataType *ds_type = NULL;
SUBTEST("Named datatypes");
try {
@@ -462,12 +463,13 @@ now.
// Create a dataset that uses the named type, then get the dataset's
// datatype and make sure it's a named type.
DataSet dset = file.createDataSet("dset1", another_type, space);
- DataType *ds_type = new DataType(dset.getDataType());
+ ds_type = new DataType(dset.getDataType());
iscommitted = ds_type->committed();
if (!iscommitted)
throw InvalidActionException("IntType::committed()", "1 Dataset type should be named type!");
dset.close();
ds_type->close();
+ delete ds_type;
// Reopen the dataset and its type, then make sure the type is
// a named type.
@@ -483,6 +485,7 @@ now.
dset = file.createDataSet("dset2", *ds_type, space);
ds_type->close();
dset.close();
+ delete ds_type;
// Reopen the second dataset and make sure the type is shared
dset = file.openDataSet("dset2");
@@ -509,6 +512,9 @@ now.
catch (Exception E) {
issue_fail_msg("test_named", __LINE__, __FILE__, E.getCDetailMsg());
}
+
+ if(ds_type)
+ delete ds_type;
} // test_named
diff --git a/c++/test/tvlstr.cpp b/c++/test/tvlstr.cpp
index 91036f9..73e54e0 100644
--- a/c++/test/tvlstr.cpp
+++ b/c++/test/tvlstr.cpp
@@ -129,7 +129,6 @@ void test_vlstr_free_custom(void *_mem, void *info)
*-------------------------------------------------------------------------
*/
// String for testing datasets
-static char *dynstring_ds_write=NULL;
static char stastring_ds_write[1]={'A'};
// Info for a string dataset
@@ -138,6 +137,9 @@ const H5std_string DSET1_DATA("String Dataset");
static void test_vlstring_dataset()
{
+ char *dynstring_ds_write = NULL;
+ char *string_ds_check = NULL;
+
// Output message about test being performed
SUBTEST("VL String on Datasets");
@@ -161,12 +163,12 @@ static void test_vlstring_dataset()
dset1.write(DSET1_DATA, vlst);
// Read and verify the dataset string as a string of chars.
- char *string_ds_check;
dset1.read(&string_ds_check, vlst);
if(HDstrcmp(string_ds_check, DSET1_DATA.c_str())!=0)
TestErrPrintf("Line %d: Attribute data different: DSET1_DATA=%s,string_ds_check=%s\n",__LINE__, DSET1_DATA.c_str(), string_ds_check);
HDfree(string_ds_check); // note: no need for std::string test
+ string_ds_check = NULL;
// Read and verify the dataset string as an std::string.
H5std_string read_str;
@@ -191,6 +193,7 @@ static void test_vlstring_dataset()
if(HDstrcmp(string_ds_check,dynstring_ds_write)!=0)
TestErrPrintf("VL string datasets don't match!, dynstring_ds_write=%s, string_ds_check=%s\n",dynstring_ds_write,string_ds_check);
HDfree(string_ds_check);
+ string_ds_check = NULL;
dset1.close();
// Open dataset DSET1_NAME again.
@@ -207,6 +210,11 @@ static void test_vlstring_dataset()
catch (Exception E) {
issue_fail_msg("test_vlstring_dataset()", __LINE__, __FILE__, E.getCDetailMsg());
}
+
+ if(dynstring_ds_write)
+ HDfree(dynstring_ds_write);
+ if(string_ds_check)
+ HDfree(string_ds_check);
} // test_vlstring_dataset()
/*-------------------------------------------------------------------------
@@ -231,10 +239,10 @@ static void test_vlstring_array_dataset()
// Output message about test being performed
SUBTEST("VL String Array on Datasets");
- H5File* file1;
+ H5File* file1 = NULL;
try {
// Create file.
- file1 = new H5File (FILENAME, H5F_ACC_RDWR);
+ file1 = new H5File(FILENAME, H5F_ACC_RDWR);
// Create dataspace for datasets.
hsize_t dims1[] = {SPACE1_DIM1};
@@ -278,8 +286,7 @@ static void test_vlstring_array_dataset()
HDmemset(wdata2, 'A', 65533);
dataset2.write(&wdata2, vlst);
- char *rdata2 = (char*)HDcalloc(65534, sizeof(char));
- HDmemset(rdata2, 0, 65533);
+ char *rdata2;
dataset2.read(&rdata2, vlst);
if (HDstrcmp(wdata2, rdata2)!=0)
TestErrPrintf("Line %d: Dataset data different: written=%s,read=%s\n",__LINE__, wdata2, rdata2);
@@ -302,8 +309,10 @@ static void test_vlstring_array_dataset()
catch (Exception E)
{
issue_fail_msg("test_vlstring_array_dataset()", __LINE__, __FILE__, E.getCDetailMsg());
- delete file1;
}
+
+ if(file1)
+ delete file1;
} // end test_vlstring_array_dataset()
/*-------------------------------------------------------------------------
@@ -482,6 +491,7 @@ static void test_vlstring_type()
// Close datatype and file.
vlst.close();
file1->close();
+ delete file1;
// Open file.
file1 = new H5File(FILENAME, H5F_ACC_RDWR);
@@ -506,8 +516,10 @@ static void test_vlstring_type()
catch (Exception E)
{
issue_fail_msg("test_vlstring_type()", __LINE__, __FILE__, E.getCDetailMsg());
- delete file1;
}
+
+ if(file1)
+ delete file1;
} // end test_vlstring_type()
/*-------------------------------------------------------------------------