https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124106

--- Comment #2 from Liam Powell <liam at liampwll dot com> ---
Disregard memory corruption issue, that's my fault. The issue in my code was
that I assumed Finalisation of a subpool removed it from the root pool. The RM
implies that this is the case but it is ambiguous so I'll go raise that with
the ARG. Specifically 13.11.5(10/30) states that "Finalization of a
Root_Storage_Pool_With_Subpools object finalizes all subpools that belong to
that pool **that have not yet been finalized**."

Below is a patch if you want to use the larger test case for the original
issue:


@@ -19,9 +19,10 @@
 --                                                                         --
 -----------------------------------------------------------------------------

+with Ada.Unchecked_Deallocate_Subpool;
 with Ada.Unchecked_Deallocation;

-package body Bounded_Indefinite_Vectors is
+package body Prunt.Bounded_Indefinite_Vectors is

    pragma Extensions_Allowed (On);

@@ -100,9 +101,16 @@ package body Bounded_Indefinite_Vectors is
    begin
       pragma Abort_Defer;

-      Clear (This);
-      Free (This.Subpool);
-      This.Subpool := null;
+      if This.Subpool /= null then
+         declare
+            Handle : Subpool_Handle := This.Subpool.all'Unchecked_Access;
+         begin
+            Clear (This);
+            Ada.Unchecked_Deallocate_Subpool (Handle);
+            Free (This.Subpool);
+            This.Subpool := null;
+         end;
+      end if;
    end Finalize;

    function Is_Empty (This : Vector) return Boolean is
@@ -228,6 +236,8 @@ package body Bounded_Indefinite_Vectors is
          if Rounded_Size > Bounded_Indefinite_Vectors.Rounded_Storage_Size
            or else Aligned >= V_Subpool.End_Address
            or else Aligned < V_Subpool.Current_Free
+           or else Aligned + Rounded_Size >= V_Subpool.End_Address
+           or else Aligned + Rounded_Size < V_Subpool.Current_Free
          then
             raise Out_Of_Space_Error with "Storage exhausted";
          end if;

Reply via email to