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.
Showing
- gcc/ada/debug.adb 4 additions, 1 deletiongcc/ada/debug.adb
- gcc/ada/exp_ch4.adb 99 additions, 24 deletionsgcc/ada/exp_ch4.adb
- gcc/ada/exp_ch4.ads 9 additions, 0 deletionsgcc/ada/exp_ch4.ads
- gcc/ada/exp_ch6.adb 15 additions, 1 deletiongcc/ada/exp_ch6.adb
- gcc/ada/exp_util.adb 5 additions, 0 deletionsgcc/ada/exp_util.adb
- gcc/ada/gen_il-fields.ads 1 addition, 0 deletionsgcc/ada/gen_il-fields.ads
- gcc/ada/gen_il-gen-gen_nodes.adb 2 additions, 1 deletiongcc/ada/gen_il-gen-gen_nodes.adb
- gcc/ada/sinfo.ads 5 additions, 0 deletionsgcc/ada/sinfo.ads
Loading
Please register or sign in to comment