Skip to content
Snippets Groups Projects
Commit 7067e6f6 authored by Eric Botcazou's avatar Eric Botcazou Committed by Marc Poulhiès
Browse files

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.
parent 6be06ae8
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment