This changes program_space::cbfd to be a gdb_bfd_ref_ptr.  This makes
it somewhat less error-prone to use, because now it manages the
reference counting automatically.
Tested by the buildbot.
2018-05-16  Tom Tromey  <tom@tromey.com>
	* gdbcore.h (core_bfd): Redefine.
	* corelow.c (core_target::close): Update.
	(core_target_open): Update.
	* progspace.h (struct program_space) <cbfd>: Now a
	gdb_bfd_ref_ptr.
+2018-05-16  Tom Tromey  <tom@tromey.com>
+
+       * gdbcore.h (core_bfd): Redefine.
+       * corelow.c (core_target::close): Update.
+       (core_target_open): Update.
+       * progspace.h (struct program_space) <cbfd>: Now a
+       gdb_bfd_ref_ptr.
+
 2018-05-16  Tom Tromey  <tom@tromey.com>
 
        PR cli/19551:
 
          comments in clear_solib in solib.c.  */
       clear_solib ();
 
-      gdb_bfd_unref (core_bfd);
-      core_bfd = NULL;
+      current_program_space->cbfd.reset (nullptr);
     }
 
   /* Core targets are heap-allocated (see core_target_open), so here
             filename.get (), bfd_errmsg (bfd_get_error ()));
     }
 
-  core_bfd = temp_bfd.release ();
+  current_program_space->cbfd = std::move (temp_bfd);
 
   core_target *target = new core_target ();
 
 
 
 /* Binary File Diddler for the core file.  */
 
-#define core_bfd (current_program_space->cbfd)
+#define core_bfd (current_program_space->cbfd.get ())
 
 /* Whether to open exec and core files read-only or read-write.  */
 
 
 
 #include "target.h"
 #include "vec.h"
+#include "gdb_bfd.h"
 #include "gdb_vecs.h"
 #include "registry.h"
 
   char *pspace_exec_filename = NULL;
 
   /* Binary file diddling handle for the core file.  */
-  bfd *cbfd = NULL;
+  gdb_bfd_ref_ptr cbfd;
 
   /* The address space attached to this program space.  More than one
      program space may be bound to the same address space.  In the