Ada: Fix finalization glitch for pools with subpools

Finalize_Pool calls Finalize_And_Deallocate on every subpool handle, but
the parameter is declared with In Out mode, so the call ends up writing
back the updated value into the node that was just deallocated.

gcc/ada/
	* libgnat/s-stposu.adb (Finalize_Pool): Pass a local copy of the
	handle in the call to Finalize_And_Deallocate.
This commit is contained in:
Eric Botcazou
2026-02-20 20:46:30 +01:00
parent 4442ed5e0e
commit fae066daab

View File

@@ -523,6 +523,7 @@ package body System.Storage_Pools.Subpools is
procedure Finalize_Pool (Pool : in out Root_Storage_Pool_With_Subpools) is procedure Finalize_Pool (Pool : in out Root_Storage_Pool_With_Subpools) is
Curr_Ptr : SP_Node_Ptr; Curr_Ptr : SP_Node_Ptr;
Ex_Occur : Exception_Occurrence; Ex_Occur : Exception_Occurrence;
Handle : Subpool_Handle;
Raised : Boolean := False; Raised : Boolean := False;
function Is_Empty_List (L : not null SP_Node_Ptr) return Boolean; function Is_Empty_List (L : not null SP_Node_Ptr) return Boolean;
@@ -557,16 +558,13 @@ package body System.Storage_Pools.Subpools is
while not Is_Empty_List (Pool.Subpools'Unchecked_Access) loop while not Is_Empty_List (Pool.Subpools'Unchecked_Access) loop
Curr_Ptr := Pool.Subpools.Next; Curr_Ptr := Pool.Subpools.Next;
-- Perform the following actions: -- Finalize and deallocate the subpool. Beware that the node pointed
-- to by Curr_Ptr will be deallocated so may not be passed as actual
-- 1) Finalize all objects chained on the subpool's master -- in the call, since the formal parameter is In Out.
-- 2) Remove the subpool from the owner's list of subpools
-- 3) Deallocate the doubly linked list node associated with the
-- subpool.
-- 4) Call Deallocate_Subpool
begin begin
Finalize_And_Deallocate (Curr_Ptr.Subpool); Handle := Curr_Ptr.Subpool;
Finalize_And_Deallocate (Handle);
exception exception
when Fin_Occur : others => when Fin_Occur : others =>