bfd/
authorTom Tromey <tromey@redhat.com>
Tue, 29 May 2012 14:23:40 +0000 (14:23 +0000)
committerTom Tromey <tromey@redhat.com>
Tue, 29 May 2012 14:23:40 +0000 (14:23 +0000)
* 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.

bfd/ChangeLog
bfd/opncls.c
gdb/ChangeLog
gdb/dwarf2read.c
gdb/exec.c
gdb/solib.c
gdb/symfile.c

index 4abe5f287fcc2c5d9bca4a87efb323f360656d0d..90f24bcb03a1bf6e1e0877bef29588a9751a9f0e 100644 (file)
@@ -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
index 9d33f3974fb0b3f214a14272463092f0a61e9860..7c1d2f99a5815990d97da36958079a91e8538946 100644 (file)
@@ -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;
     }
index 7677154f43249b06da744efb5719dc2aa98594d8..c089f038f8c0d3aabe507185a9ccf8e5925de920 100644 (file)
@@ -1,3 +1,13 @@
+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...
index 53100c519bca21f9be64e25bbbca709b6ef92258..8dbc53e9111891eaf68f087a46ae18e087ef4a83 100644 (file)
@@ -6957,7 +6957,6 @@ try_open_dwo_file (const char *file_name)
   sym_bfd = bfd_fopen (absolute_name, gnutarget, FOPEN_RB, desc);
   if (!sym_bfd)
     {
-      close (desc);
       xfree (absolute_name);
       return NULL;
     }
index 58fb55e2bf7ae1546f0051e64d892fb8370008d3..6ba198615f1322552128690f00effa7c72af6d0c 100644 (file)
@@ -238,7 +238,6 @@ exec_file_attach (char *filename, int from_tty)
 
       if (!exec_bfd)
        {
-         close (scratch_chan);
          error (_("\"%s\": could not open as an executable file: %s"),
                 scratch_pathname, bfd_errmsg (bfd_get_error ()));
        }
index 656e8dfa5518442f959e965e5bf2e7176886a4f5..90439ba584df76fab8ae9d4bfb53c9f32a1e4aba 100644 (file)
@@ -380,8 +380,6 @@ solib_bfd_fopen (char *pathname, int fd)
 
       if (abfd)
        bfd_set_cacheable (abfd, 1);
-      else if (fd != -1)
-       close (fd);
     }
 
   if (!abfd)
index 416d35d13c34efdda5e02e5dd90cd78bb82bd370..31da4e4842d86294e5589dc25a6b2cafd622a2eb 100644 (file)
@@ -1764,7 +1764,6 @@ symfile_bfd_open (char *name)
   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 ()));
This page took 0.040551 seconds and 4 git commands to generate.