This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
[jankratochvil-misc] Fix double free on error while inserting thebreakpoint
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: archer at sourceware dot org
- Date: Sat, 22 Nov 2008 22:28:52 +0100
- Subject: [jankratochvil-misc] Fix double free on error while inserting thebreakpoint
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
2008-11-22 Jan Kratochvil <jan.kratochvil@redhat.com>
Fix double free on error while 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.
---
gdb/breakpoint.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 847dbdd..69c0619 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -5265,8 +5265,6 @@ create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
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
@@ -5587,7 +5585,6 @@ break_command_really (char *arg, char *cond_string, int thread,
b->condition_not_parsed = 1;
b->ops = ops;
- update_global_location_list (1);
mention (b);
}
@@ -5599,6 +5596,11 @@ break_command_really (char *arg, char *cond_string, int thread,
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.
--
1.6.0.3