This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Fix double free on error while inserting the breakpoint


Hi,

SEGV reproducer:

x86 requires to build GDB with -lmcheck to make the crash reproducible.
Therefore no testsuite testcase is provided.
./gdb -nx -ex start -ex 'set breakpoint always-inserted on' -ex 'b *0' -ex 'delete 2' ./gdb

(Found on ia64 without -lmcheck.)


Regards,
Jan
2008-11-22  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix double free on error inserting the breakpoint instruction.
	* breakpoint.c (create_breakpoints): Move the
	update_global_location_list call to ...
	(break_command_really): ... here together with the second local call
	both unified after all the cleanups.

--- gdb/breakpoint.c	22 Nov 2008 04:41:45 -0000	1.362
+++ gdb/breakpoint.c	22 Nov 2008 20:10:07 -0000
@@ -5257,8 +5257,6 @@ create_breakpoints (struct symtabs_and_l
 			 cond_string, type, disposition,
 			 thread, ignore_count, ops, from_tty);
     }
-
-  update_global_location_list (1);
 }
 
 /* Parse ARG which is assumed to be a SAL specification possibly
@@ -5579,7 +5577,6 @@ break_command_really (char *arg, char *c
       b->condition_not_parsed = 1;
       b->ops = ops;
 
-      update_global_location_list (1);
       mention (b);
     }
   
@@ -5591,6 +5588,11 @@ break_command_really (char *arg, char *c
   discard_cleanups (breakpoint_chain);
   /* But cleanup everything else. */
   do_cleanups (old_chain);
+
+  /* Have already BREAKPOINT_CHAIN discarded as we may get an exception while
+     inserting the breakpoints which would double-free the resources both by
+     BREAKPOINT_CHAIN now and during DELETE_BREAKPOINT in the future.  */
+  update_global_location_list (1);
 }
 
 /* Set a breakpoint. 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]