Use gdb::unique_xmalloc_ptr when calling tilde_expand

This patch changes most sites calling tilde_expand to use
gdb::unique_xmalloc_ptr, rather than a cleanup.  It also changes
scan_expression_with_cleanup to return a unique pointer, because the
patch was already touching code in that area.

Regression tested on the buildbot.

ChangeLog
2017-08-05  Tom Tromey  <tom@tromey.com>

	* compile/compile-object-load.c (compile_object_load): Use
	gdb::unique_xmalloc_ptr.
	* cli/cli-dump.c (scan_filename): Rename from
	scan_filename_with_cleanup.  Change return type.
	(scan_expression): Rename from scan_expression_with_cleanup.
	Change return type.
	(dump_memory_to_file, dump_value_to_file, restore_command):
	Use gdb::unique_xmalloc_ptr.  Update.
	* cli/cli-cmds.c (find_and_open_script): Use
	gdb::unique_xmalloc_ptr.
	* tracefile-tfile.c (tfile_open): Use gdb::unique_xmalloc_ptr.
	* symmisc.c (maintenance_print_symbols)
	(maintenance_print_msymbols): Use gdb::unique_xmalloc_ptr.
	* symfile.c (symfile_bfd_open, generic_load)
	(add_symbol_file_command, remove_symbol_file_command): Use
	gdb::unique_xmalloc_ptr.
	* source.c (openp): Use gdb::unique_xmalloc_ptr.
	* psymtab.c (maintenance_print_psymbols): Use
	gdb::unique_xmalloc_ptr.
	* corelow.c (core_open): Use gdb::unique_xmalloc_ptr.
	* breakpoint.c (save_breakpoints): Use gdb::unique_xmalloc_ptr.
	* solib.c (solib_map_sections): Use gdb::unique_xmalloc_ptr.
	(reload_shared_libraries_1): Likewise.
This commit is contained in:
Tom Tromey
2017-07-31 15:49:21 -06:00
parent fdffd6f411
commit ee0c32930c
12 changed files with 129 additions and 203 deletions

View File

@@ -516,14 +516,11 @@ show_script_ext_mode (struct ui_file *file, int from_tty,
gdb::optional<open_script>
find_and_open_script (const char *script_file, int search_path)
{
char *file;
int fd;
struct cleanup *old_cleanups;
int search_flags = OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH;
gdb::optional<open_script> opened;
file = tilde_expand (script_file);
old_cleanups = make_cleanup (xfree, file);
gdb::unique_xmalloc_ptr<char> file (tilde_expand (script_file));
if (search_path)
search_flags |= OPF_SEARCH_IN_PATH;
@@ -532,18 +529,11 @@ find_and_open_script (const char *script_file, int search_path)
files. Put the full location in *FULL_PATHP. */
char *temp_path;
fd = openp (source_path, search_flags,
file, O_RDONLY, &temp_path);
file.get (), O_RDONLY, &temp_path);
gdb::unique_xmalloc_ptr<char> full_path (temp_path);
if (fd == -1)
{
int save_errno = errno;
do_cleanups (old_cleanups);
errno = save_errno;
return opened;
}
do_cleanups (old_cleanups);
return opened;
FILE *result = fdopen (fd, FOPEN_RT);
if (result == NULL)