Fix double free when running gdb.linespec/ls-errs.exp (PR breakpoints/21553)

The problem is that b->extra_string is free'ed twice: Once in the
breakpoint's dtor, and another time via make_cleanup (xfree).

This patch gets rid of the cleanups, fixing the problem.

Tested on x86_64 GNU/Linux.

gdb/ChangeLog:
2017-06-06  Pedro Alves  <palves@redhat.com>

	PR breakpoints/21553
	* breakpoint.c (create_breakpoints_sal_default)
	(init_breakpoint_sal, create_breakpoint_sal): Use
	gdb::unique_xmalloc_ptr for string parameters.
	(create_breakpoint): Constify 'extra_string' and 'cond_string'
	parameters.  Replace cleanups with gdb::unique_xmalloc_ptr.
	(base_breakpoint_create_breakpoints_sal)
	(bkpt_create_breakpoints_sal, tracepoint_create_breakpoints_sal)
	(strace_marker_create_breakpoints_sal)
	(create_breakpoints_sal_default): Use gdb::unique_xmalloc_ptr for
	string parameters.
	* breakpoint.h (breakpoint_ops::create_breakpoints_sal): Use
	gdb::unique_xmalloc_ptr for string parameters.
	(create_breakpoint): Constify 'extra_string' and 'cond_string'
	parameters.
This commit is contained in:
Pedro Alves
2017-06-06 15:53:59 +01:00
parent fbe654c8bc
commit e1e01040aa
3 changed files with 80 additions and 64 deletions

View File

@@ -604,7 +604,8 @@ struct breakpoint_ops
This function is called inside `create_breakpoint'. */
void (*create_breakpoints_sal) (struct gdbarch *,
struct linespec_result *,
char *, char *,
gdb::unique_xmalloc_ptr<char>,
gdb::unique_xmalloc_ptr<char>,
enum bptype, enum bpdisp, int, int,
int, const struct breakpoint_ops *,
int, int, int, unsigned);
@@ -1329,8 +1330,8 @@ enum breakpoint_create_flags
extern int create_breakpoint (struct gdbarch *gdbarch,
const struct event_location *location,
char *cond_string, int thread,
char *extra_string,
const char *cond_string, int thread,
const char *extra_string,
int parse_extra,
int tempflag, enum bptype wanted_type,
int ignore_count,