Return unique_xmalloc_ptr from some solib.c functions

This changes a couple of solib.c functions -- exec_file_find and
solib_find -- to return a unique_xmalloc_ptr, and then fixes up the
users.  This allows the removal of some cleanups.

This also changes solib_bfd_open to not take ownership of its
argument.  I think this change is somewhat cleaner.

gdb/ChangeLog
2018-02-14  Tom Tromey  <tom@tromey.com>

	* solist.h (exec_file_find, solib_find): Return
	unique_xmalloc_ptr.
	(solib_bfd_fopen): Take a const char *.
	* solib.c (solib_find_1): Return unique_xmalloc_ptr.
	(exec_file_find, solib_find): Likewise.
	(solib_bfd_fopen): Do not take ownership of "pathname".
	(solib_bfd_open): Use unique_xmalloc_ptr.
	* solib-darwin.c (darwin_bfd_open): Use unique_xmalloc_ptr.
	* solib-aix.c (solib_aix_bfd_open): Use unique_xmalloc_ptr.
	* infrun.c (follow_exec): Use unique_xmalloc_ptr.
	* exec.c (exec_file_locate_attach): Use unique_xmalloc_ptr.
This commit is contained in:
Tom Tromey 2017-11-10 13:07:46 -07:00
parent 12ef3f5a7c
commit 797bc1cb25
7 changed files with 56 additions and 51 deletions

View file

@ -614,7 +614,6 @@ solib_aix_bfd_open (char *pathname)
char *sep;
int filename_len;
int found_file;
char *found_pathname;
if (pathname[path_len - 1] != ')')
return solib_bfd_open (pathname);
@ -638,10 +637,12 @@ solib_aix_bfd_open (char *pathname)
/* Calling solib_find makes certain that sysroot path is set properly
if program has a dependency on .a archive and sysroot is set via
set sysroot command. */
found_pathname = solib_find (filename.c_str (), &found_file);
gdb::unique_xmalloc_ptr<char> found_pathname
= solib_find (filename.c_str (), &found_file);
if (found_pathname == NULL)
perror_with_name (pathname);
gdb_bfd_ref_ptr archive_bfd (solib_bfd_fopen (found_pathname, found_file));
gdb_bfd_ref_ptr archive_bfd (solib_bfd_fopen (found_pathname.get (),
found_file));
if (archive_bfd == NULL)
{
warning (_("Could not open `%s' as an executable file: %s"),