1 commit b339543c6cac043f087b51fd859186e77f757f85
2 Author: Nick Clifton <nickc@redhat.com>
3 Date: Wed Aug 1 14:34:41 2018 +0100
5 Close resource leaks in the BFD library's plugin handler.
8 * plugin.c (bfd_plugin_open_input): Close file descriptor if the
10 (try_claim): Always close the file descriptor at the end of the
12 (try_load_plugin): If a plugin has already been registered, then
13 skip the dlopen and onload steps and go straight to claiming the
14 file. If these is an error, close the plugin.
16 diff --git a/bfd/ChangeLog b/bfd/ChangeLog
17 index d3831b7a65..457c00e6bd 100644
21 +2018-08-01 Zenith <zenith432@users.sourceforge.net>
24 + * plugin.c (bfd_plugin_open_input): Close file descriptor if the
25 + call to fstat fails.
26 + (try_claim): Always close the file descriptor at the end of the
28 + (try_load_plugin): If a plugin has already been registered, then
29 + skip the dlopen and onload steps and go straight to claiming the
30 + file. If these is an error, close the plugin.
32 2018-07-18 Nick Clifton <nickc@redhat.com>
35 diff --git a/bfd/plugin.c b/bfd/plugin.c
36 index 7c5bba22c7..d9b9e2f174 100644
39 @@ -124,7 +124,7 @@ message (int level ATTRIBUTE_UNUSED,
42 /* Register a claim-file handler. */
43 -static ld_plugin_claim_file_handler claim_file;
44 +static ld_plugin_claim_file_handler claim_file = NULL;
46 static enum ld_plugin_status
47 register_claim_file (ld_plugin_claim_file_handler handler)
48 @@ -186,8 +186,13 @@ bfd_plugin_open_input (bfd *ibfd, struct ld_plugin_input_file *file)
53 if (fstat (file->fd, &stat_buf))
61 file->filesize = stat_buf.st_size;
63 @@ -208,21 +213,24 @@ try_claim (bfd *abfd)
65 if (!bfd_plugin_open_input (abfd, &file))
67 - claim_file (&file, &claimed);
71 + claim_file (&file, &claimed);
77 try_load_plugin (const char *pname, bfd *abfd, int *has_plugin_p)
79 - void *plugin_handle;
80 + void *plugin_handle = NULL;
81 struct ld_plugin_tv tv[4];
83 ld_plugin_onload onload;
84 enum ld_plugin_status status;
87 + goto have_claim_file;
91 plugin_handle = dlopen (pname, RTLD_NOW);
92 @@ -257,6 +265,7 @@ try_load_plugin (const char *pname, bfd *abfd, int *has_plugin_p)
93 if (status != LDPS_OK)
99 abfd->plugin_format = bfd_plugin_no;
100 @@ -272,6 +281,9 @@ try_load_plugin (const char *pname, bfd *abfd, int *has_plugin_p)
105 + dlclose (plugin_handle);
106 + register_claim_file (NULL);
110 @@ -362,7 +374,7 @@ load_plugin (bfd *abfd)
113 full_name = concat (p, "/", ent->d_name, NULL);
114 - if (stat(full_name, &s) == 0 && S_ISREG (s.st_mode))
115 + if (stat (full_name, &s) == 0 && S_ISREG (s.st_mode))
116 found = try_load_plugin (full_name, abfd, &valid_plugin);
118 has_plugin = valid_plugin;