From 6234c0dee27daa5450d140fc9189135ac2ae0fa8 Mon Sep 17 00:00:00 2001 From: Raymond Lu Date: Tue, 27 Mar 2012 12:03:32 -0500 Subject: [svn-r22156] Issue 7785 - Writing or reading many small chunks ran out of memory and caused seg fault. I added checks in two places to make sure the library returns error stack when it fails to allocate memory. I didn't add any test to the test suite since there is no good way to test it. But I tested and verified the error stack by hand. Tested on jam - this is a merge from the trunk. --- release_docs/RELEASE.txt | 4 ++++ src/H5Dchunk.c | 2 +- src/H5Dio.c | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 372ce45..d68d517 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -118,6 +118,10 @@ Bug Fixes since HDF5-1.8.8 Library ------- + - When an application tries to write or read many small data chunks and + runs out of memory, the library had a seg fault. The fix is to + return the error stack with proper information. (SLU - 2012/3/23. + Issue 7785) - H5Pset_data_transform had seg fault in some cases like x*-100. It works correctly now and handles other cases like 100-x or 2/x. (SLU - 2012/3/15. Issue 7922) diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c index 4d70337..335298d 100644 --- a/src/H5Dchunk.c +++ b/src/H5Dchunk.c @@ -974,7 +974,7 @@ H5D_free_chunk_info(void *item, void UNUSED *key, void UNUSED *opdata) H5S_select_all(chunk_info->fspace, TRUE); /* Close the chunk's memory dataspace, if it's not shared */ - if(!chunk_info->mspace_shared) + if(!chunk_info->mspace_shared && chunk_info->mspace) (void)H5S_close(chunk_info->mspace); /* Free the actual chunk info */ diff --git a/src/H5Dio.c b/src/H5Dio.c index 9fece3a..2c0c2e0 100644 --- a/src/H5Dio.c +++ b/src/H5Dio.c @@ -433,6 +433,7 @@ H5D_read(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, || dataset->shared->layout.type == H5D_COMPACT); /* Call storage method's I/O initialization routine */ + HDmemset(&fm, 0, sizeof(H5D_chunk_map_t)); if(io_info.layout_ops.io_init && (*io_info.layout_ops.io_init)(&io_info, &type_info, nelmts, file_space, mem_space, &fm) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't initialize I/O info") io_op_init = TRUE; @@ -656,6 +657,7 @@ H5D_write(H5D_t *dataset, hid_t mem_type_id, const H5S_t *mem_space, #endif /*H5_HAVE_PARALLEL*/ /* Call storage method's I/O initialization routine */ + HDmemset(&fm, 0, sizeof(H5D_chunk_map_t)); if(io_info.layout_ops.io_init && (*io_info.layout_ops.io_init)(&io_info, &type_info, nelmts, file_space, mem_space, &fm) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "can't initialize I/O info") io_op_init = TRUE; -- cgit v0.12