summaryrefslogtreecommitdiffstats
path: root/c++/test/tvlstr.cpp
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/tvlstr.cpp
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/tvlstr.cpp')
-rw-r--r--c++/test/tvlstr.cpp28
1 files changed, 20 insertions, 8 deletions
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()
/*-------------------------------------------------------------------------