From 26fcd5d7572ea1bf0cc697158969749420900e0b Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 28 Apr 2017 23:34:32 -0600 Subject: Use containers to avoid cleanups This patch introduces the use of various containers -- std::vector, std::string, or gdb::byte_vector -- in several spots in gdb that were using xmalloc and a cleanup. ChangeLog 2017-08-03 Tom Tromey * valops.c (search_struct_method): Use gdb::byte_vector. * valarith.c (value_concat): Use std::vector. * target.c (memory_xfer_partial): Use gdb::byte_vector. (simple_search_memory): Likewise. * printcmd.c (find_string_backward): Use gdb::byte_vector. * mi/mi-main.c (mi_cmd_data_write_memory): Use gdb::byte_vector. * gcore.c (gcore_copy_callback): Use gdb::byte_vector. * elfread.c (elf_rel_plt_read): Use std::string. * cp-valprint.c (cp_print_value): Use gdb::byte_vector. * cli/cli-dump.c (restore_section_callback): Use gdb::byte_vector. --- gdb/mi/mi-main.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'gdb/mi') diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index a4c6ec9..0bf587f 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -1659,8 +1659,6 @@ mi_cmd_data_write_memory (const char *command, char **argv, int argc) /* FIXME: ezannoni 2000-02-17 LONGEST could possibly not be big enough when using a compiler other than GCC. */ LONGEST value; - gdb_byte *buffer; - struct cleanup *old_chain; long offset = 0; int oind = 0; char *oarg; @@ -1707,13 +1705,10 @@ mi_cmd_data_write_memory (const char *command, char **argv, int argc) /* Get the value as a number. */ value = parse_and_eval_address (argv[3]); /* Get the value into an array. */ - buffer = (gdb_byte *) xmalloc (word_size); - old_chain = make_cleanup (xfree, buffer); - store_signed_integer (buffer, word_size, byte_order, value); + gdb::byte_vector buffer (word_size); + store_signed_integer (buffer.data (), word_size, byte_order, value); /* Write it down to memory. */ - write_memory_with_notification (addr, buffer, word_size); - /* Free the buffer. */ - do_cleanups (old_chain); + write_memory_with_notification (addr, buffer.data (), word_size); } /* Implementation of the -data-write-memory-bytes command. -- cgit v1.1