From 528e15722bf67d126e17218708c0314bcfadbf6a Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 7 Aug 2018 17:43:08 -0400 Subject: Replace some uses of xstrprintf with string_printf This patch replaces some simple uses of xstrprintf with with string_printf, removing the need to do manual memory freeing. The change in ada-lang.c fixes an apparent memory leak. Regtested on the buildbot. gdb/ChangeLog: * common/filestuff.h (gdb_fopen_cloexec): New overload. (gdb_open_cloexec): Likewise. * nat/linux-osdata.c (command_from_pid): Use string_printf. (commandline_from_pid): Likewise. (linux_xfer_osdata_threads): Likewise. (linux_xfer_osdata_fds): Likewise. * ada-lang.c (is_package_name): Likewise. * auxv.c (procfs_xfer_auxv): Likewise. * breakpoint.c (print_one_breakpoint_location): Use uiout::field_fmt. (print_one_catch_solib): Use string_printf. * coff-pe-read.c (add_pe_exported_sym): Likewise. (add_pe_forwarded_sym): Likewise. * dwarf2read.c (create_type_unit_group): Likewise. (build_error_marker_type): Likewise. * infcall.c (get_function_name): Likewise. * valprint.c (print_converted_chars_to_obstack): Likewise. * xtensa-tdep.c (xtensa_register_type): Likewise. --- gdb/common/filestuff.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'gdb/common') diff --git a/gdb/common/filestuff.h b/gdb/common/filestuff.h index 0e46eb5..1a09c72 100644 --- a/gdb/common/filestuff.h +++ b/gdb/common/filestuff.h @@ -48,6 +48,16 @@ extern void close_most_fds (void); extern int gdb_open_cloexec (const char *filename, int flags, /* mode_t */ unsigned long mode); +/* Convenience wrapper for the above, which takes the filename as an + std::string. */ + +static inline int +gdb_open_cloexec (const std::string &filename, int flags, + /* mode_t */ unsigned long mode) +{ + return gdb_open_cloexec (filename.c_str (), flags, mode); +} + struct gdb_file_deleter { void operator() (FILE *file) const @@ -66,6 +76,15 @@ typedef std::unique_ptr gdb_file_up; extern gdb_file_up gdb_fopen_cloexec (const char *filename, const char *opentype); +/* Convenience wrapper for the above, which takes the filename as an + std::string. */ + +static inline gdb_file_up +gdb_fopen_cloexec (const std::string &filename, const char *opentype) +{ + return gdb_fopen_cloexec (filename.c_str (), opentype); +} + /* Like 'socketpair', but ensures that the returned file descriptors have the close-on-exec flag set. */ -- cgit v1.1