Plug one of many possible memory leaks in error handling.
This commit is contained in:
parent
53d2c54b5b
commit
c4920b9772
@ -1,3 +1,8 @@
|
|||||||
|
2000-10-25 Chris Demetriou <cgd@sibyte.com>
|
||||||
|
|
||||||
|
* ieee.c (ieee_archive_p): Plug one of many possible
|
||||||
|
memory leaks in error handling.
|
||||||
|
|
||||||
2000-10-20 Jakub Jelinek <jakub@redhat.com>
|
2000-10-20 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
||||||
* elf32-sparc.c (elf32_sparc_merge_private_bfd_data,
|
* elf32-sparc.c (elf32_sparc_merge_private_bfd_data,
|
||||||
|
53
bfd/ieee.c
53
bfd/ieee.c
@ -1343,27 +1343,21 @@ ieee_archive_p (abfd)
|
|||||||
ieee->h.abfd = abfd;
|
ieee->h.abfd = abfd;
|
||||||
|
|
||||||
if (this_byte (&(ieee->h)) != Module_Beginning)
|
if (this_byte (&(ieee->h)) != Module_Beginning)
|
||||||
{
|
goto got_wrong_format_error;
|
||||||
abfd->tdata.ieee_ar_data = save;
|
|
||||||
goto got_wrong_format_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
next_byte (&(ieee->h));
|
next_byte (&(ieee->h));
|
||||||
library = read_id (&(ieee->h));
|
library = read_id (&(ieee->h));
|
||||||
if (strcmp (library, "LIBRARY") != 0)
|
if (strcmp (library, "LIBRARY") != 0)
|
||||||
{
|
goto got_wrong_format_error;
|
||||||
bfd_release (abfd, ieee);
|
|
||||||
abfd->tdata.ieee_ar_data = save;
|
/* Throw away the filename. */
|
||||||
goto got_wrong_format_error;
|
|
||||||
}
|
|
||||||
/* Throw away the filename */
|
|
||||||
read_id (&(ieee->h));
|
read_id (&(ieee->h));
|
||||||
|
|
||||||
ieee->element_count = 0;
|
ieee->element_count = 0;
|
||||||
ieee->element_index = 0;
|
ieee->element_index = 0;
|
||||||
|
|
||||||
next_byte (&(ieee->h)); /* Drop the ad part */
|
next_byte (&(ieee->h)); /* Drop the ad part. */
|
||||||
must_parse_int (&(ieee->h)); /* And the two dummy numbers */
|
must_parse_int (&(ieee->h)); /* And the two dummy numbers. */
|
||||||
must_parse_int (&(ieee->h));
|
must_parse_int (&(ieee->h));
|
||||||
|
|
||||||
alc_elts = 10;
|
alc_elts = 10;
|
||||||
@ -1371,7 +1365,7 @@ ieee_archive_p (abfd)
|
|||||||
if (elts == NULL)
|
if (elts == NULL)
|
||||||
goto error_return;
|
goto error_return;
|
||||||
|
|
||||||
/* Read the index of the BB table */
|
/* Read the index of the BB table. */
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
int rec;
|
int rec;
|
||||||
@ -1400,14 +1394,14 @@ ieee_archive_p (abfd)
|
|||||||
t->file_offset = must_parse_int (&(ieee->h));
|
t->file_offset = must_parse_int (&(ieee->h));
|
||||||
t->abfd = (bfd *) NULL;
|
t->abfd = (bfd *) NULL;
|
||||||
|
|
||||||
/* Make sure that we don't go over the end of the buffer */
|
/* Make sure that we don't go over the end of the buffer. */
|
||||||
|
|
||||||
if ((size_t) ieee_pos (abfd) > sizeof (buffer) / 2)
|
if ((size_t) ieee_pos (abfd) > sizeof (buffer) / 2)
|
||||||
{
|
{
|
||||||
/* Past half way, reseek and reprime */
|
/* Past half way, reseek and reprime. */
|
||||||
buffer_offset += ieee_pos (abfd);
|
buffer_offset += ieee_pos (abfd);
|
||||||
if (bfd_seek (abfd, buffer_offset, SEEK_SET) != 0)
|
if (bfd_seek (abfd, buffer_offset, SEEK_SET) != 0)
|
||||||
goto error_return;
|
goto error_return;
|
||||||
|
|
||||||
/* FIXME: Check return value. I'm not sure whether it needs
|
/* FIXME: Check return value. I'm not sure whether it needs
|
||||||
to read the entire buffer or not. */
|
to read the entire buffer or not. */
|
||||||
bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
|
bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
|
||||||
@ -1421,36 +1415,33 @@ ieee_archive_p (abfd)
|
|||||||
ieee->element_count * sizeof *ieee->elements));
|
ieee->element_count * sizeof *ieee->elements));
|
||||||
if (ieee->elements == NULL)
|
if (ieee->elements == NULL)
|
||||||
goto error_return;
|
goto error_return;
|
||||||
|
|
||||||
memcpy (ieee->elements, elts,
|
memcpy (ieee->elements, elts,
|
||||||
ieee->element_count * sizeof *ieee->elements);
|
ieee->element_count * sizeof *ieee->elements);
|
||||||
free (elts);
|
free (elts);
|
||||||
elts = NULL;
|
elts = NULL;
|
||||||
|
|
||||||
/* Now scan the area again, and replace BB offsets with file */
|
/* Now scan the area again, and replace BB offsets with file offsets. */
|
||||||
/* offsets */
|
|
||||||
|
|
||||||
for (i = 2; i < ieee->element_count; i++)
|
for (i = 2; i < ieee->element_count; i++)
|
||||||
{
|
{
|
||||||
if (bfd_seek (abfd, ieee->elements[i].file_offset, SEEK_SET) != 0)
|
if (bfd_seek (abfd, ieee->elements[i].file_offset, SEEK_SET) != 0)
|
||||||
goto error_return;
|
goto error_return;
|
||||||
|
|
||||||
/* FIXME: Check return value. I'm not sure whether it needs to
|
/* FIXME: Check return value. I'm not sure whether it needs to
|
||||||
read the entire buffer or not. */
|
read the entire buffer or not. */
|
||||||
bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
|
bfd_read ((PTR) buffer, 1, sizeof (buffer), abfd);
|
||||||
ieee->h.first_byte = buffer;
|
ieee->h.first_byte = buffer;
|
||||||
ieee->h.input_p = buffer;
|
ieee->h.input_p = buffer;
|
||||||
|
|
||||||
next_byte (&(ieee->h)); /* Drop F8 */
|
next_byte (&(ieee->h)); /* Drop F8. */
|
||||||
next_byte (&(ieee->h)); /* Drop 14 */
|
next_byte (&(ieee->h)); /* Drop 14. */
|
||||||
must_parse_int (&(ieee->h)); /* Drop size of block */
|
must_parse_int (&(ieee->h)); /* Drop size of block. */
|
||||||
|
|
||||||
if (must_parse_int (&(ieee->h)) != 0)
|
if (must_parse_int (&(ieee->h)) != 0)
|
||||||
{
|
/* This object has been deleted. */
|
||||||
/* This object has been deleted */
|
ieee->elements[i].file_offset = 0;
|
||||||
ieee->elements[i].file_offset = 0;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
ieee->elements[i].file_offset = must_parse_int (&(ieee->h));
|
||||||
ieee->elements[i].file_offset = must_parse_int (&(ieee->h));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* abfd->has_armap = ;*/
|
/* abfd->has_armap = ;*/
|
||||||
@ -1458,10 +1449,14 @@ ieee_archive_p (abfd)
|
|||||||
return abfd->xvec;
|
return abfd->xvec;
|
||||||
|
|
||||||
got_wrong_format_error:
|
got_wrong_format_error:
|
||||||
|
bfd_release (abfd, ieee);
|
||||||
|
abfd->tdata.ieee_ar_data = save;
|
||||||
bfd_set_error (bfd_error_wrong_format);
|
bfd_set_error (bfd_error_wrong_format);
|
||||||
|
|
||||||
error_return:
|
error_return:
|
||||||
if (elts != NULL)
|
if (elts != NULL)
|
||||||
free (elts);
|
free (elts);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user