From 953cff563058831ab0bf863c7655d23b5e6a5989 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 15 Oct 2019 10:57:40 -0600 Subject: Change gcc_target_options to return std::string This patch was inspired by a recent review that recommended using std::string in a new implementation of the gcc_target_options gdbarch function. It changes this function to return std::string rather than an ordinary xmalloc'd string. I believe this caught a latent memory leak in compile.c:get_args. Tested on x86-64 Fedora 29. gdb/ChangeLog 2019-10-15 Tom Tromey * gdbarch.h, gdbarch.c: Rebuild. * gdbarch.sh (gcc_target_options): Change return type to std::string. * compile/compile.c (get_args): Update. * nios2-tdep.c (nios2_gcc_target_options): Return std::string. * arm-linux-tdep.c (arm_linux_gcc_target_options): Return std::string. * aarch64-linux-tdep.c (aarch64_linux_gcc_target_options): Return std::string. * arch-utils.c (default_gcc_target_options): Return std::string. * arch-utils.h (default_gcc_target_options): Return std::string. * s390-tdep.c (s390_gcc_target_options): Return std::string. Change-Id: I51f61703426a323089e646da8f22320a2cafbc1f --- gdb/gdbarch.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gdb/gdbarch.h') diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h index 3c6efae..01b5aef 100644 --- a/gdb/gdbarch.h +++ b/gdb/gdbarch.h @@ -1596,10 +1596,10 @@ extern void set_gdbarch_infcall_munmap (struct gdbarch *gdbarch, gdbarch_infcall /* Return string (caller has to use xfree for it) with options for GCC to produce code for this target, typically "-m64", "-m32" or "-m31". These options are put before CU's DW_AT_producer compilation options so that - they can override it. Method may also return NULL. */ + they can override it. */ -typedef char * (gdbarch_gcc_target_options_ftype) (struct gdbarch *gdbarch); -extern char * gdbarch_gcc_target_options (struct gdbarch *gdbarch); +typedef std::string (gdbarch_gcc_target_options_ftype) (struct gdbarch *gdbarch); +extern std::string gdbarch_gcc_target_options (struct gdbarch *gdbarch); extern void set_gdbarch_gcc_target_options (struct gdbarch *gdbarch, gdbarch_gcc_target_options_ftype *gcc_target_options); /* Return a regular expression that matches names used by this -- cgit v1.1