https://gcc.gnu.org/g:48a6fcfee02343bc42ca8367f6c635158993f271
commit r16-9135-g48a6fcfee02343bc42ca8367f6c635158993f271 Author: Eric Botcazou <[email protected]> Date: Fri May 29 08:34:39 2026 +0200 ada: Fix dangling reference with Bounded_Indefinite_Holders and Empty_Holder The issue is that the finalization of an empty container does not deallocate its subpool, thus creating a dangling reference to it from the global pool. gcc/ada/ChangeLog: * libgnat/a-cbinho.adb (Clear): Deallocate the subpool even if the container is empty. Diff: --- gcc/ada/libgnat/a-cbinho.adb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gcc/ada/libgnat/a-cbinho.adb b/gcc/ada/libgnat/a-cbinho.adb index 5c5a8ed4139a..43a9f8b85280 100644 --- a/gcc/ada/libgnat/a-cbinho.adb +++ b/gcc/ada/libgnat/a-cbinho.adb @@ -75,13 +75,13 @@ package body Ada.Containers.Bounded_Indefinite_Holders is procedure Clear (Container : in out Holder) is begin - if Is_Empty (Container) then - return; -- nothing to do - end if; - if Container.Busy /= 0 then - raise Program_Error with "attempt to tamper with elements"; + if not Is_Empty (Container) then + if Container.Busy /= 0 then + raise Program_Error with "attempt to tamper with elements"; + end if; + Free (Container.Element); -- finalize element end if; - Free (Container.Element); -- finalize element + -- Unconditionally deallocate the subpool for Finalize, see below Ada.Unchecked_Deallocate_Subpool (Container.Handle); end Clear;
