@@ -99,32 +99,37 @@ CUTEST_TEST_TEST(mmap) {
9999 cbytes = blosc2_schunk_append_buffer (schunk_write_mmap , data_buffer2 , sizeof (data_buffer2 ));
100100 CUTEST_ASSERT ("Could not write second chunk" , cbytes > 0 );
101101
102- blosc2_schunk_free (schunk_write_default );
103- blosc2_schunk_free (schunk_write_mmap );
102+ CUTEST_ASSERT ( "Could not free the schunk ressources" , blosc2_schunk_free (schunk_write_default ) == 0 );
103+ CUTEST_ASSERT ( "Could not free the schunk ressources" , blosc2_schunk_free (schunk_write_mmap ) == 0 );
104104
105105 /* The compressed file content should not depend on the I/O which created it */
106106 CUTEST_ASSERT ("Files are not identical" , are_files_identical (urlpath_default , urlpath_mmap ));
107107
108108 /* Read the schunk data back again (using mmap) */
109- mmap_file = BLOSC2_STDIO_MMAP_DEFAULTS ;
110- mmap_file .mode = "r" ;
111- mmap_file .initial_mapping_size = initial_mapping_size ;
112- io .params = & mmap_file ;
113- blosc2_schunk * schunk_read = blosc2_schunk_open_udio (urlpath_mmap , & io );
114- CUTEST_ASSERT ("Mismatch in number of chunks" , schunk_read -> nchunks == 2 );
115-
116- float * chunk_data = (float * )malloc (schunk_read -> chunksize );
117- int dsize = blosc2_schunk_decompress_chunk (schunk_read , 0 , chunk_data , schunk_read -> chunksize );
118- CUTEST_ASSERT ("Size of decompressed chunk 1 does not match" , dsize == sizeof (data_buffer ));
119- CUTEST_ASSERT ("Value 1 of chunk 1 is wrong" , fabs (chunk_data [0 ] - 0.1 ) < 1e-6 );
120- CUTEST_ASSERT ("Value 2 of chunk 1 is wrong" , fabs (chunk_data [1 ] - 0.2 ) < 1e-6 );
121-
122- dsize = blosc2_schunk_decompress_chunk (schunk_read , 1 , chunk_data , schunk_read -> chunksize );
123- CUTEST_ASSERT ("Size of decompressed chunk 1 does not match" , dsize == sizeof (data_buffer2 ));
124- CUTEST_ASSERT ("Value 1 of chunk 2 is wrong" , fabs (chunk_data [0 ] - 0.3 ) < 1e-6 );
125- CUTEST_ASSERT ("Value 2 of chunk 2 is wrong" , fabs (chunk_data [1 ] - 0.4 ) < 1e-6 );
126-
127- blosc2_schunk_free (schunk_read );
109+ int n_repeated_reads = 2 ; // Make sure reading the same file again does not lead to any problems
110+ int dsize ;
111+ float * chunk_data ;
112+ for (int i = 0 ; i < n_repeated_reads ; i ++ ) {
113+ mmap_file = BLOSC2_STDIO_MMAP_DEFAULTS ;
114+ mmap_file .mode = "r" ;
115+ mmap_file .initial_mapping_size = initial_mapping_size ;
116+ io .params = & mmap_file ;
117+ blosc2_schunk * schunk_read = blosc2_schunk_open_udio (urlpath_mmap , & io );
118+ CUTEST_ASSERT ("Mismatch in number of chunks" , schunk_read -> nchunks == 2 );
119+
120+ chunk_data = (float * )malloc (schunk_read -> chunksize );
121+ dsize = blosc2_schunk_decompress_chunk (schunk_read , 0 , chunk_data , schunk_read -> chunksize );
122+ CUTEST_ASSERT ("Size of decompressed chunk 1 does not match" , dsize == sizeof (data_buffer ));
123+ CUTEST_ASSERT ("Value 1 of chunk 1 is wrong" , fabs (chunk_data [0 ] - 0.1 ) < 1e-6 );
124+ CUTEST_ASSERT ("Value 2 of chunk 1 is wrong" , fabs (chunk_data [1 ] - 0.2 ) < 1e-6 );
125+
126+ dsize = blosc2_schunk_decompress_chunk (schunk_read , 1 , chunk_data , schunk_read -> chunksize );
127+ CUTEST_ASSERT ("Size of decompressed chunk 1 does not match" , dsize == sizeof (data_buffer2 ));
128+ CUTEST_ASSERT ("Value 1 of chunk 2 is wrong" , fabs (chunk_data [0 ] - 0.3 ) < 1e-6 );
129+ CUTEST_ASSERT ("Value 2 of chunk 2 is wrong" , fabs (chunk_data [1 ] - 0.4 ) < 1e-6 );
130+
131+ CUTEST_ASSERT ("Could not free the schunk ressources" , blosc2_schunk_free (schunk_read ) == 0 );
132+ }
128133
129134#if defined(__linux__ )
130135 /* Append some data to the existing schunk in memory (does not work on Windows) */
@@ -148,7 +153,7 @@ CUTEST_TEST_TEST(mmap) {
148153 CUTEST_ASSERT ("Value 1 of chunk 2 is wrong" , fabs (chunk_data [0 ] - 0.5 ) < 1e-6 );
149154 CUTEST_ASSERT ("Value 2 of chunk 2 is wrong" , fabs (chunk_data [1 ] - 0.6 ) < 1e-6 );
150155
151- blosc2_schunk_free (schunk_memory );
156+ CUTEST_ASSERT ( "Could not free the schunk ressources" , blosc2_schunk_free (schunk_memory ) == 0 );
152157 CUTEST_ASSERT ("Files are not identical" , are_files_identical (urlpath_default , urlpath_mmap ));
153158#endif
154159
@@ -173,7 +178,7 @@ CUTEST_TEST_TEST(mmap) {
173178 CUTEST_ASSERT ("Value 1 of chunk 2 is wrong" , fabs (chunk_data [0 ] - 0.5 ) < 1e-6 );
174179 CUTEST_ASSERT ("Value 2 of chunk 2 is wrong" , fabs (chunk_data [1 ] - 0.6 ) < 1e-6 );
175180
176- blosc2_schunk_free (schunk_append );
181+ CUTEST_ASSERT ( "Could not free the schunk ressources" , blosc2_schunk_free (schunk_append ) == 0 );
177182 CUTEST_ASSERT ("Files are identical" , !are_files_identical (urlpath_default , urlpath_mmap ));
178183
179184 free (chunk_data );
0 commit comments