summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/H5Z.c21
-rw-r--r--test/tmisc.c43
2 files changed, 64 insertions, 0 deletions
diff --git a/src/H5Z.c b/src/H5Z.c
index 66b81a6..dfeb2b5 100644
--- a/src/H5Z.c
+++ b/src/H5Z.c
@@ -787,6 +787,19 @@ H5Z_append(H5O_pline_t *pline, H5Z_filter_t filter, unsigned flags,
/* Allocate additional space in the pipeline if it's full */
if(pline->nused >= pline->nalloc) {
H5O_pline_t x;
+ size_t n;
+
+ /* Each filter's data may be stored internally or may be
+ * a separate block of memory.
+ * For each filter, if cd_values points to the internal array
+ * _cd_values, the pointer will need to be updated when the
+ * filter struct is reallocated. Set these pointers to NULL
+ * so that we can reset them after reallocating the filters array.
+ */
+ for(n=0; n<pline->nalloc; ++n) {
+ if(pline->filter[n].cd_values == pline->filter[n]._cd_values)
+ pline->filter[n].cd_values = NULL;
+ }
x.nalloc = MAX(H5Z_MAX_NFILTERS, 2 * pline->nalloc);
x.filter = H5MM_realloc(pline->filter, x.nalloc*sizeof(x.filter[0]));
@@ -794,6 +807,14 @@ H5Z_append(H5O_pline_t *pline, H5Z_filter_t filter, unsigned flags,
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for filter pipeline")
pline->nalloc = x.nalloc;
pline->filter = x.filter;
+
+ /* Fix pointers in filters that need to point to their own internal
+ * data.
+ */
+ for(n=0; n<pline->nalloc; ++n) {
+ if(NULL == pline->filter[n].cd_values)
+ pline->filter[n].cd_values = pline->filter[n]._cd_values;
+ }
} /* end if */
/* Add the new filter to the pipeline */
diff --git a/test/tmisc.c b/test/tmisc.c
index 3625681..20489fe 100644
--- a/test/tmisc.c
+++ b/test/tmisc.c
@@ -4643,6 +4643,47 @@ test_misc25b(void)
/****************************************************************
**
+** test_misc26(): Regression test: ensure that copying filter
+** pipelines works properly.
+**
+****************************************************************/
+static void
+test_misc26(void)
+{
+ hid_t dcpl1, dcpl2; /* Property List IDs */
+ herr_t ret; /* Generic return value */
+
+ /* Output message about test being performed */
+ MESSAGE(5, ("Copying filter pipelines\n"));
+
+ /* Create the property list */
+ dcpl1 = H5Pcreate(H5P_DATASET_CREATE);
+ CHECK_I(dcpl1, "H5Pcreate");
+
+ /* Add a filter to the property list */
+ ret = H5Pset_deflate(dcpl1, 1);
+ CHECK_I(ret, "H5Pset_deflate");
+
+ /* Copy the property list */
+ dcpl2 = H5Pcopy(dcpl1);
+ CHECK_I(dcpl2, "H5Pcopy");
+
+ /* Add a filter to the copy */
+ ret = H5Pset_shuffle(dcpl2);
+ CHECK_I(ret, "H5Pset_shuffle");
+
+ /* Close the property lists. If adding the second filter to
+ * dcpl2 caused it to be in an inconsistent state, closing it
+ * will trip an assert.
+ */
+ ret = H5Pclose(dcpl1);
+ CHECK_I(ret, "H5Pclose");
+ ret = H5Pclose(dcpl2);
+ CHECK_I(ret, "H5Pclose");
+}
+
+/****************************************************************
+**
** test_misc(): Main misc. test routine.
**
****************************************************************/
@@ -4680,6 +4721,8 @@ test_misc(void)
test_misc24(); /* Test inappropriate API opens of objects */
test_misc25a(); /* Exercise null object header message merge bug */
test_misc25b(); /* Exercise null object header message merge bug on existing file */
+ test_misc26(); /* Test closing property lists with long filter pipelines */
+
} /* test_misc() */