From e83e4e24021acb4b095b1e8a45a51c2ea088a1ed Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 27 Mar 2018 14:31:10 -0600 Subject: Change target_read_string to use unique_xmalloc_ptr This changes the out parameter of target_read_string to be a unique_xmalloc_ptr. This avoids a cleanup and sets the stage for more cleanup removals. This patch also removes a seemingly needless alloca from print_subexp_standard. gdb/ChangeLog 2018-03-30 Tom Tromey * windows-nat.c (handle_output_debug_string, handle_exception): Update. * target.h (target_read_string): Update. * target.c (target_read_string): Change "string" to unique_xmalloc_ptr. * solib-svr4.c (open_symbol_file_object, svr4_read_so_list): Update. * solib-frv.c (frv_current_sos): Update. * solib-dsbt.c (dsbt_current_sos): Update. * solib-darwin.c (darwin_current_sos): Update. * linux-thread-db.c (inferior_has_bug): Update. * expprint.c (print_subexp_standard) : Update. Remove alloca. * ada-lang.c (ada_main_name): Update. --- gdb/solib-svr4.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'gdb/solib-svr4.c') diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 29e74daa51a..d8d047d3949 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -990,7 +990,7 @@ static int open_symbol_file_object (int from_tty) { CORE_ADDR lm, l_name; - char *filename; + gdb::unique_xmalloc_ptr filename; int errcode; struct link_map_offsets *lmo = svr4_fetch_link_map_offsets (); struct type *ptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr; @@ -1040,7 +1040,6 @@ open_symbol_file_object (int from_tty) /* Now fetch the filename from target memory. */ target_read_string (l_name, &filename, SO_NAME_MAX_PATH_SIZE - 1, &errcode); - make_cleanup (xfree, filename); if (errcode) { @@ -1051,7 +1050,7 @@ open_symbol_file_object (int from_tty) } /* Have a pathname: read the symbol file. */ - symbol_file_add_main (filename, add_flags); + symbol_file_add_main (filename.get (), add_flags); do_cleanups (cleanups); return 1; @@ -1339,7 +1338,7 @@ svr4_read_so_list (CORE_ADDR lm, CORE_ADDR prev_lm, for (; lm != 0; prev_lm = lm, lm = next_lm) { int errcode; - char *buffer; + gdb::unique_xmalloc_ptr buffer; so_list_up newobj (XCNEW (struct so_list)); @@ -1387,10 +1386,9 @@ svr4_read_so_list (CORE_ADDR lm, CORE_ADDR prev_lm, continue; } - strncpy (newobj->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1); + strncpy (newobj->so_name, buffer.get (), SO_NAME_MAX_PATH_SIZE - 1); newobj->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0'; strcpy (newobj->so_original_name, newobj->so_name); - xfree (buffer); /* If this entry has no name, or its name matches the name for the main executable, don't include it in the list. */ -- cgit v1.2.1