/* opncls.c -- open and close a BFD.
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
- 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+ 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012
Free Software Foundation, Inc.
Written by Cygnus Support.
If <<NULL>> is returned then an error has occured. Possible errors
are <<bfd_error_no_memory>>, <<bfd_error_invalid_target>> or
<<system_call>> error.
+
+ On error, @var{fd} is always closed.
*/
bfd *
nbfd = _bfd_new_bfd ();
if (nbfd == NULL)
- return NULL;
+ {
+ if (fd != -1)
+ close (fd);
+ return NULL;
+ }
target_vec = bfd_find_target (target, nbfd);
if (target_vec == NULL)
{
+ if (fd != -1)
+ close (fd);
_bfd_delete_bfd (nbfd);
return NULL;
}
Possible errors are <<bfd_error_no_memory>>,
<<bfd_error_invalid_target>> and <<bfd_error_system_call>>.
+
+ On error, @var{fd} is closed.
*/
bfd *
fdflags = fcntl (fd, F_GETFL, NULL);
if (fdflags == -1)
{
+ int save = errno;
+
+ close (fd);
+ errno = save;
bfd_set_error (bfd_error_system_call);
return NULL;
}
+2012-05-29 Tom Tromey <tromey@redhat.com>
+
+ * symfile.c (symfile_bfd_open): Don't close desc if bfd_fopen
+ fails.
+ * solib.c (solib_bfd_fopen): Don't close fd if bfd_fopen fails.
+ * exec.c (exec_file_attach): Don't close scratch_chan if bfd_fopen
+ fails.
+ * dwarf2read.c (try_open_dwo_file): Don't close fd if bfd_fopen
+ fails.
+
2012-05-29 Tristan Gingold <gingold@adacore.com>
* solib-darwin.c (dyld_all_image_addr, dyld_all_image): Move into...
sym_bfd = bfd_fopen (name, gnutarget, FOPEN_RB, desc);
if (!sym_bfd)
{
- close (desc);
make_cleanup (xfree, name);
error (_("`%s': can't open to read symbols: %s."), name,
bfd_errmsg (bfd_get_error ()));