]> git.ipfire.org Git - thirdparty/gcc.git/commit
ada: Fix memory leak when failing to initialize newly allocated memory
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 10 Dec 2024 18:43:14 +0000 (19:43 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 6 Jan 2025 09:14:48 +0000 (10:14 +0100)
commit7067e6f6ff9bf9c640a8f1e3193fad195d20f6c3
treee648a79663e5cf5bcb1171edec3a39c7b2289dfc
parent6be06ae88b8be8543094d712f24c52a4d2d73220
ada: Fix memory leak when failing to initialize newly allocated memory

This makes the compiler generate cleanup code to deallocate the memory when
the evaluation of the expression of an allocator raises an exception, if the
expression is a call to a function that may raise, i.e. is not declared with
the No_Raise aspect/pragma.  This can also be disabled by means of -gnatdQ.

gcc/ada/ChangeLog:

* debug.adb (dQ): Document usage.
* exp_ch4.ads (Build_Cleanup_For_Allocator): New declaration.
* exp_ch4.adb (Build_Cleanup_For_Allocator): New procedure.
(Expand_Allocator_Expression): Build a cleanup to deallocate the
memory when the evaluation of the expression raises an exception.
* exp_ch6.adb (Make_Build_In_Place_Call_In_Allocator): Likewise.
* exp_util.adb (Build_Allocate_Deallocate_Proc): Do not generate the
detachment if the deallocation is for the cleanup of an allocator.
* gen_il-fields.ads (Opt_Field_Enum): Add For_Allocator.
* gen_il-gen-gen_nodes.adb (N_Free_Statement): Likewise.
* sinfo.ads (For_Allocator): Document usage on N_Free_Statement.
gcc/ada/debug.adb
gcc/ada/exp_ch4.adb
gcc/ada/exp_ch4.ads
gcc/ada/exp_ch6.adb
gcc/ada/exp_util.adb
gcc/ada/gen_il-fields.ads
gcc/ada/gen_il-gen-gen_nodes.adb
gcc/ada/sinfo.ads