diff mbox

[committed] PR 63280: Misplaced destructor call

Message ID 87mw9ql7fl.fsf@e105548-lin.cambridge.arm.com
State New
Headers show

Commit Message

Richard Sandiford Sept. 23, 2014, 2:47 p.m. UTC
My patch to fix a memory leak with target_globals accidentally
introduced a double destructor call for default_target_ira.  Normally
this was benign because free_register_move_costs clears the freed
pointers afterwards.  However, with LTO -O3 that clearing could get
inlined into the destructor and removed as dead, leading to a double free.

Tested on aarch64-elf and applied as obvious.

Thanks,
Richard


gcc/
	PR bootstrap/63280
	* target-globals.c (target_globals::~target_globals): Fix location
	of ira_int destruction.
diff mbox

Patch

Index: gcc/target-globals.c
===================================================================
--- gcc/target-globals.c	2014-09-22 08:37:01.421320931 +0100
+++ gcc/target-globals.c	2014-09-23 15:44:48.951451849 +0100
@@ -121,10 +121,10 @@  save_target_globals_default_opts ()
 
 target_globals::~target_globals ()
 {
-  ira_int->~target_ira_int ();
   /* default_target_globals points to static data so shouldn't be freed.  */
   if (this != &default_target_globals)
     {
+      ira_int->~target_ira_int ();
       hard_regs->finalize ();
       XDELETE (flag_state);
       XDELETE (regs);