diff options
author | Tom Tromey <tromey@redhat.com> | 2012-05-29 14:23:30 +0000 |
---|---|---|
committer | Tom Tromey <tromey@redhat.com> | 2012-05-29 14:23:30 +0000 |
commit | 0d90ccbd77a966359356df38a744144fe06b221d (patch) | |
tree | dbb2f04960446f88b2c72dc32cad4245648d7e01 /bfd | |
parent | bf01fd59c660b995b81fd291d83e170b7bfc1254 (diff) | |
download | binutils-redhat-0d90ccbd77a966359356df38a744144fe06b221d.tar.gz |
bfd/
* opncls.c (bfd_fopen): Always close fd on failure.
(bfd_fdopenr): Likewise.
gdb/
* 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.
Diffstat (limited to 'bfd')
-rw-r--r-- | bfd/ChangeLog | 5 | ||||
-rw-r--r-- | bfd/opncls.c | 18 |
2 files changed, 21 insertions, 2 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 4abe5f287f..90f24bcb03 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,8 @@ +2012-05-29 Tom Tromey <tromey@redhat.com> + + * opncls.c (bfd_fopen): Always close fd on failure. + (bfd_fdopenr): Likewise. + 2012-05-27 Alan Modra <amodra@gmail.com> PR ld/14170 diff --git a/bfd/opncls.c b/bfd/opncls.c index 9d33f3974f..7c1d2f99a5 100644 --- a/bfd/opncls.c +++ b/bfd/opncls.c @@ -1,6 +1,6 @@ /* 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. @@ -190,6 +190,8 @@ DESCRIPTION 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 * @@ -200,11 +202,17 @@ bfd_fopen (const char *filename, const char *target, const char *mode, int fd) 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; } @@ -307,6 +315,8 @@ DESCRIPTION Possible errors are <<bfd_error_no_memory>>, <<bfd_error_invalid_target>> and <<bfd_error_system_call>>. + + On error, @var{fd} is closed. */ bfd * @@ -323,6 +333,10 @@ bfd_fdopenr (const char *filename, const char *target, int fd) 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; } |