]> git.ipfire.org Git - thirdparty/gcc.git/commit
ada: Fix containers' Reference_Preserving_Key functions' memory leaks
authorSteve Baird <baird@adacore.com>
Wed, 6 Mar 2024 22:27:44 +0000 (14:27 -0800)
committerMarc Poulhiès <poulhies@adacore.com>
Fri, 17 May 2024 08:21:02 +0000 (10:21 +0200)
commitecf17346ff112ccf58cd2920a23fa756b068e1bc
treea1198ae8230973cde90a084526a1a3db59ba670f
parentbf935572b076b822033cf1e9d31312c75e4c90d3
ada: Fix containers' Reference_Preserving_Key functions' memory leaks

Fix memory leaks in containers' Reference_Preserving_Key functions

Make the same change in each of 3 Ada.Containers child units: Ordered_Sets,
Indefinite_Ordered_Sets, and Bounded_Ordered_Sets. The function
Reference_Preserving_Key evaluates an allocator of type Key_Access whose
storage was not being reclaimed. Update the Finalize procedure for
type Reference_Control_Type to free that storage. But this change introduces
a possible erroneous double-free situation if an object is copied (because
the original and the copy will each be finalized at some point). So also
introduce an Adjust procedure which allocates a copy of the allocated object.
Another possible solution to this problem (which is not being implemented
yet) is based on implementing AI22-0082. Also include a fix for a bug in
Sem_Util.Has_Some_Controlled_Component that was discovered while working
on this.

gcc/ada/

* sem_util.adb (Has_Some_Controlled_Component): Fix a bug which
causes (in some cases involving a Disable_Controlled aspect
specification) Needs_Finalization to return different answers for
one type depending on whether the function is called before or
after the type is frozen.
* libgnat/a-coorse.ads: Type Control_Reference_Type gets an Adjust
procedure.
* libgnat/a-cborse.ads: Likewise.
* libgnat/a-ciorse.ads: Likewise
* libgnat/a-coorse.adb:
(Finalize): Reclaim allocated Key_Type object.
(Adjust): New procedure; prevent sharing of non-null Key_Access
values by allocating a copy.
* libgnat/a-cborse.adb: Likewise.
* libgnat/a-ciorse.adb: Likewise.
gcc/ada/libgnat/a-cborse.adb
gcc/ada/libgnat/a-cborse.ads
gcc/ada/libgnat/a-ciorse.adb
gcc/ada/libgnat/a-ciorse.ads
gcc/ada/libgnat/a-coorse.adb
gcc/ada/libgnat/a-coorse.ads
gcc/ada/sem_util.adb