@@ -599,7 +599,8 @@ H5MF__close_fstype(H5F_t *f, H5F_mem_page_t type)
599599 *------------------------------------------------------------------------- 
600600 */ 
601601herr_t 
602- H5MF__add_sect (H5F_t  * f , H5FD_mem_t  alloc_type , H5FS_t  * fspace , H5MF_free_section_t  * node )
602+ H5MF__add_sect (H5F_t  * f , H5FD_mem_t  alloc_type , H5FS_t  * fspace , H5MF_free_section_t  * node ,
603+                bool  * merged_or_shrunk )
603604{
604605    H5AC_ring_t     orig_ring  =  H5AC_RING_INV ; /* Original ring value */ 
605606    H5AC_ring_t     fsm_ring   =  H5AC_RING_INV ; /* Ring of FSM */ 
@@ -631,7 +632,8 @@ H5MF__add_sect(H5F_t *f, H5FD_mem_t alloc_type, H5FS_t *fspace, H5MF_free_sectio
631632            __func__ , node -> sect_info .addr , node -> sect_info .size );
632633#endif  /* H5MF_ALLOC_DEBUG_MORE */ 
633634    /* Add the section */ 
634-     if  (H5FS_sect_add (f , fspace , (H5FS_section_info_t  * )node , H5FS_ADD_RETURNED_SPACE , & udata ) <  0 )
635+     if  (H5FS_sect_add (f , fspace , (H5FS_section_info_t  * )node , H5FS_ADD_RETURNED_SPACE , & udata ,
636+                       merged_or_shrunk ) <  0 )
635637        HGOTO_ERROR (H5E_RESOURCE , H5E_CANTINSERT , FAIL , "can't re-add section to file free space" );
636638
637639done :
@@ -711,8 +713,11 @@ H5MF__find_sect(H5F_t *f, H5FD_mem_t alloc_type, hsize_t size, H5FS_t *fspace, h
711713#endif  /* H5MF_ALLOC_DEBUG_MORE */ 
712714
713715            /* Re-add the section to the free-space manager */ 
714-             if  (H5MF__add_sect (f , alloc_type , fspace , node ) <  0 )
716+             if  (H5MF__add_sect (f , alloc_type , fspace , node , NULL ) <  0 ) {
717+                 node -> sect_info .addr  -=  size ;
718+                 node -> sect_info .size  +=  size ;
715719                HGOTO_ERROR (H5E_RESOURCE , H5E_CANTINSERT , FAIL , "can't re-add section to file free space" );
720+             }
716721        } /* end else */ 
717722    }     /* end if */ 
718723
@@ -852,9 +857,10 @@ H5MF_alloc(H5F_t *f, H5FD_mem_t alloc_type, hsize_t size)
852857static  haddr_t 
853858H5MF__alloc_pagefs (H5F_t  * f , H5FD_mem_t  alloc_type , hsize_t  size )
854859{
855-     H5F_mem_page_t        ptype ;                   /* Free-space manager type */ 
856-     H5MF_free_section_t  * node       =  NULL ;        /* Free space section pointer */ 
857-     haddr_t               ret_value  =  HADDR_UNDEF ; /* Return value */ 
860+     H5F_mem_page_t        ptype ;                     /* Free-space manager type */ 
861+     H5MF_free_section_t  * node         =  NULL ;        /* Free space section pointer */ 
862+     bool     section_merged_or_shrunk  =  false;       /* Whether free space section was merged or shrunk away */ 
863+     haddr_t  ret_value                 =  HADDR_UNDEF ; /* Return value */ 
858864
859865    FUNC_ENTER_PACKAGE 
860866
@@ -900,9 +906,13 @@ H5MF__alloc_pagefs(H5F_t *f, H5FD_mem_t alloc_type, hsize_t size)
900906                                "can't initialize free space section" );
901907
902908                /* Add the fragment to the large free-space manager */ 
903-                 if  (H5MF__add_sect (f , alloc_type , f -> shared -> fs_man [ptype ], node ) <  0 )
909+                 if  (H5MF__add_sect (f , alloc_type , f -> shared -> fs_man [ptype ], node , & section_merged_or_shrunk ) < 
910+                     0 ) {
911+                     if  (section_merged_or_shrunk )
912+                         node  =  NULL ;
904913                    HGOTO_ERROR (H5E_RESOURCE , H5E_CANTINSERT , HADDR_UNDEF ,
905914                                "can't re-add section to file free space" );
915+                 }
906916
907917                node  =  NULL ;
908918            } /* end if */ 
@@ -931,9 +941,13 @@ H5MF__alloc_pagefs(H5F_t *f, H5FD_mem_t alloc_type, hsize_t size)
931941                HGOTO_ERROR (H5E_RESOURCE , H5E_CANTINIT , HADDR_UNDEF , "can't initialize free space section" );
932942
933943            /* Add the remaining space in the page to the manager */ 
934-             if  (H5MF__add_sect (f , alloc_type , f -> shared -> fs_man [ptype ], node ) <  0 )
944+             if  (H5MF__add_sect (f , alloc_type , f -> shared -> fs_man [ptype ], node , & section_merged_or_shrunk ) < 
945+                 0 ) {
946+                 if  (section_merged_or_shrunk )
947+                     node  =  NULL ;
935948                HGOTO_ERROR (H5E_RESOURCE , H5E_CANTINSERT , HADDR_UNDEF ,
936949                            "can't re-add section to file free space" );
950+             }
937951
938952            node  =  NULL ;
939953
@@ -1154,15 +1168,21 @@ H5MF_xfree(H5F_t *f, H5FD_mem_t alloc_type, haddr_t addr, hsize_t size)
11541168
11551169    /* If size of the freed section is larger than threshold, add it to the free space manager */ 
11561170    if  (size  >= f -> shared -> fs_threshold ) {
1171+         bool  section_merged_or_shrunk  =  false; /* Whether free space section was merged or shrunk away */ 
1172+ 
11571173        assert (f -> shared -> fs_man [fs_type ]);
11581174
11591175#ifdef  H5MF_ALLOC_DEBUG_MORE 
11601176        fprintf (stderr , "%s: Before H5FS_sect_add()\n" , __func__ );
11611177#endif  /* H5MF_ALLOC_DEBUG_MORE */ 
11621178
11631179        /* Add to the free space for the file */ 
1164-         if  (H5MF__add_sect (f , alloc_type , f -> shared -> fs_man [fs_type ], node ) <  0 )
1180+         if  (H5MF__add_sect (f , alloc_type , f -> shared -> fs_man [fs_type ], node , & section_merged_or_shrunk ) <  0 ) {
1181+             if  (section_merged_or_shrunk )
1182+                 node  =  NULL ;
11651183            HGOTO_ERROR (H5E_RESOURCE , H5E_CANTINSERT , FAIL , "can't add section to file free space" );
1184+         }
1185+ 
11661186        node  =  NULL ;
11671187
11681188#ifdef  H5MF_ALLOC_DEBUG_MORE 
@@ -1316,7 +1336,7 @@ H5MF_try_extend(H5F_t *f, H5FD_mem_t alloc_type, haddr_t addr, hsize_t size, hsi
13161336                HGOTO_ERROR (H5E_RESOURCE , H5E_CANTINIT , FAIL , "can't initialize free space section" );
13171337
13181338            /* Add the fragment to the large-sized free-space manager */ 
1319-             if  (H5MF__add_sect (f , alloc_type , f -> shared -> fs_man [fs_type ], node ) <  0 )
1339+             if  (H5MF__add_sect (f , alloc_type , f -> shared -> fs_man [fs_type ], node ,  NULL ) <  0 )
13201340                HGOTO_ERROR (H5E_RESOURCE , H5E_CANTINSERT , FAIL , "can't re-add section to file free space" );
13211341
13221342            node  =  NULL ;
@@ -3059,8 +3079,13 @@ H5MF_settle_meta_data_fsm(H5F_t *f, bool *fsm_settled)
30593079        assert (sm_fssinfo_fs_type  >  H5F_MEM_PAGE_DEFAULT );
30603080        assert (sm_fssinfo_fs_type  <  H5F_MEM_PAGE_LARGE_SUPER );
30613081
3062-         assert (!H5_addr_defined (f -> shared -> fs_addr [sm_fshdr_fs_type ]));
3063-         assert (!H5_addr_defined (f -> shared -> fs_addr [sm_fssinfo_fs_type ]));
3082+         if  (H5_addr_defined (f -> shared -> fs_addr [sm_fshdr_fs_type ]))
3083+             HGOTO_ERROR (H5E_FSPACE , H5E_BADVALUE , FAIL ,
3084+                         "small free space header block manager should not have had file space allocated" );
3085+         if  (H5_addr_defined (f -> shared -> fs_addr [sm_fssinfo_fs_type ]))
3086+             HGOTO_ERROR (
3087+                 H5E_FSPACE , H5E_BADVALUE , FAIL ,
3088+                 "small free space serialized section manager should not have had file space allocated" );
30643089
30653090        /* Note that in most cases, sm_hdr_fspace will equal sm_sinfo_fspace. */ 
30663091        sm_hdr_fspace    =  f -> shared -> fs_man [sm_fshdr_fs_type ];
@@ -3078,8 +3103,13 @@ H5MF_settle_meta_data_fsm(H5F_t *f, bool *fsm_settled)
30783103            assert (lg_fssinfo_fs_type  >= H5F_MEM_PAGE_LARGE_SUPER );
30793104            assert (lg_fssinfo_fs_type  <  H5F_MEM_PAGE_NTYPES );
30803105
3081-             assert (!H5_addr_defined (f -> shared -> fs_addr [lg_fshdr_fs_type ]));
3082-             assert (!H5_addr_defined (f -> shared -> fs_addr [lg_fssinfo_fs_type ]));
3106+             if  (H5_addr_defined (f -> shared -> fs_addr [lg_fshdr_fs_type ]))
3107+                 HGOTO_ERROR (H5E_FSPACE , H5E_BADVALUE , FAIL ,
3108+                             "large free space header block manager should not have had file space allocated" );
3109+             if  (H5_addr_defined (f -> shared -> fs_addr [lg_fssinfo_fs_type ]))
3110+                 HGOTO_ERROR (
3111+                     H5E_FSPACE , H5E_BADVALUE , FAIL ,
3112+                     "large free space serialized section manager should not have had file space allocated" );
30833113
30843114            /* Note that in most cases, lg_hdr_fspace will equal lg_sinfo_fspace. */ 
30853115            lg_hdr_fspace    =  f -> shared -> fs_man [lg_fshdr_fs_type ];
0 commit comments