[gcc r17-1635] ada: Fix dangling reference with Bounded_Indefinite_Holders and Empty_Holder
Marc Poulhies
dkm@gcc.gnu.org
Thu Jun 18 08:05:28 GMT 2026
https://gcc.gnu.org/g:fb323d7f046139fc9ef31a51355fe83240a61cfb
commit r17-1635-gfb323d7f046139fc9ef31a51355fe83240a61cfb
Author: Eric Botcazou <ebotcazou@adacore.com>
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;
More information about the Gcc-cvs
mailing list