GNU Binutils with patches for OS216
修訂 | 0ab2f69a4317b0c133eebac46f1f3eb39f3f7b77 (tree) |
---|---|
時間 | 2000-04-08 05:27:29 |
作者 | Michael Snyder <msnyder@vmwa...> |
Commiter | Michael Snyder |
2000-04-06 Michael Snyder <msnyder@seadog.cygnus.com>
@@ -1,3 +1,9 @@ | ||
1 | +2000-04-06 Michael Snyder <msnyder@seadog.cygnus.com> | |
2 | + | |
3 | + * elfcore.h (elf_core_file_p): preserve value of tdata at entry, | |
4 | + and restore it on failure. Release newly allocated tdata on | |
5 | + failure. | |
6 | + | |
1 | 7 | Fri Apr 7 11:33:47 2000 Jim Wilson <wilson@cygnus.com> |
2 | 8 | |
3 | 9 | * dwarf2.c (struct dwarf2_debug): New field dwarf_line_size. |
@@ -83,9 +83,11 @@ elf_core_file_p (abfd) | ||
83 | 83 | { |
84 | 84 | Elf_External_Ehdr x_ehdr; /* Elf file header, external form */ |
85 | 85 | Elf_Internal_Ehdr *i_ehdrp; /* Elf file header, internal form */ |
86 | - Elf_Internal_Phdr *i_phdrp; /* Elf program header, internal form */ | |
86 | + Elf_Internal_Phdr *i_phdrp = NULL; /* Elf program header, internal form */ | |
87 | 87 | unsigned int phindex; |
88 | 88 | struct elf_backend_data *ebd; |
89 | + struct elf_obj_tdata *preserved_tdata = elf_tdata (abfd); | |
90 | + struct elf_obj_tdata *new_tdata = NULL; | |
89 | 91 | |
90 | 92 | /* Read in the ELF header in external format. */ |
91 | 93 | if (bfd_read ((PTR) & x_ehdr, sizeof (x_ehdr), 1, abfd) != sizeof (x_ehdr)) |
@@ -98,9 +100,7 @@ elf_core_file_p (abfd) | ||
98 | 100 | /* Check the magic number. */ |
99 | 101 | if (elf_file_p (&x_ehdr) == false) |
100 | 102 | { |
101 | - wrong: | |
102 | - bfd_set_error (bfd_error_wrong_format); | |
103 | - return NULL; | |
103 | + goto wrong; | |
104 | 104 | } |
105 | 105 | |
106 | 106 | /* FIXME: Check EI_VERSION here ! */ |
@@ -125,12 +125,11 @@ elf_core_file_p (abfd) | ||
125 | 125 | } |
126 | 126 | |
127 | 127 | /* Give abfd an elf_obj_tdata. */ |
128 | - elf_tdata (abfd) = | |
128 | + new_tdata = | |
129 | 129 | (struct elf_obj_tdata *) bfd_zalloc (abfd, sizeof (struct elf_obj_tdata)); |
130 | - if (elf_tdata (abfd) == NULL) | |
130 | + if (new_tdata == NULL) | |
131 | 131 | return NULL; |
132 | - | |
133 | - /* FIXME: from here on down, "goto wrong" will leak memory. */ | |
132 | + elf_tdata (abfd) = new_tdata; | |
134 | 133 | |
135 | 134 | /* Swap in the rest of the header, now that we have the byte order. */ |
136 | 135 | i_ehdrp = elf_elfheader (abfd); |
@@ -189,7 +188,7 @@ elf_core_file_p (abfd) | ||
189 | 188 | i_phdrp = (Elf_Internal_Phdr *) |
190 | 189 | bfd_alloc (abfd, sizeof (*i_phdrp) * i_ehdrp->e_phnum); |
191 | 190 | if (!i_phdrp) |
192 | - return NULL; | |
191 | + goto fail; | |
193 | 192 | |
194 | 193 | elf_tdata (abfd)->phdr = i_phdrp; |
195 | 194 |
@@ -199,7 +198,7 @@ elf_core_file_p (abfd) | ||
199 | 198 | Elf_External_Phdr x_phdr; |
200 | 199 | if (bfd_read ((PTR) &x_phdr, sizeof (x_phdr), 1, abfd) |
201 | 200 | != sizeof (x_phdr)) |
202 | - return NULL; | |
201 | + goto fail; | |
203 | 202 | |
204 | 203 | elf_swap_phdr_in (abfd, &x_phdr, i_phdrp + phindex); |
205 | 204 | } |
@@ -208,7 +207,7 @@ elf_core_file_p (abfd) | ||
208 | 207 | for (phindex = 0; phindex < i_ehdrp->e_phnum; ++phindex) |
209 | 208 | { |
210 | 209 | if (!_bfd_elfcore_section_from_phdr (abfd, i_phdrp + phindex, phindex)) |
211 | - return NULL; | |
210 | + goto fail; | |
212 | 211 | } |
213 | 212 | |
214 | 213 | /* Set the machine architecture. */ |
@@ -216,7 +215,7 @@ elf_core_file_p (abfd) | ||
216 | 215 | { |
217 | 216 | /* It's OK if this fails for the generic target. */ |
218 | 217 | if (ebd->elf_machine_code != EM_NONE) |
219 | - return NULL; | |
218 | + goto fail; | |
220 | 219 | } |
221 | 220 | |
222 | 221 | /* Save the entry point from the ELF header. */ |
@@ -231,4 +230,14 @@ elf_core_file_p (abfd) | ||
231 | 230 | } |
232 | 231 | |
233 | 232 | return abfd->xvec; |
233 | + | |
234 | +wrong: | |
235 | + bfd_set_error (bfd_error_wrong_format); | |
236 | +fail: | |
237 | + if (i_phdrp != NULL) | |
238 | + bfd_release (abfd, i_phdrp); | |
239 | + if (new_tdata != NULL) | |
240 | + bfd_release (abfd, new_tdata); | |
241 | + elf_tdata (abfd) = preserved_tdata; | |
242 | + return NULL; | |
234 | 243 | } |