aboutsummaryrefslogtreecommitdiff
path: root/binutils
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@airs.com>2003-08-11 16:34:18 +0000
committerIan Lance Taylor <ian@airs.com>2003-08-11 16:34:18 +0000
commitd989285ca3dddb7c8e1a36a7e3d93d9f58c5756b (patch)
treeedea9ac691dcef7588191f39ee07077df97782a3 /binutils
parent15f40dfc73fc065fd6f203ea56fc8edbcd6736f0 (diff)
downloadgdb-d989285ca3dddb7c8e1a36a7e3d93d9f58c5756b.zip
gdb-d989285ca3dddb7c8e1a36a7e3d93d9f58c5756b.tar.gz
gdb-d989285ca3dddb7c8e1a36a7e3d93d9f58c5756b.tar.bz2
* readelf.c (process_archive): Fix error handling. Remove memory
leak.
Diffstat (limited to 'binutils')
-rw-r--r--binutils/ChangeLog5
-rw-r--r--binutils/readelf.c26
2 files changed, 22 insertions, 9 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index e0e1d13..2d7d376 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,4 +1,7 @@
-2003-08-11 Ian Lance Taylor <ian@airs.com>
+2003-08-11 Ian Lance Taylor <ian@airs.com>
+
+ * readelf.c (process_archive): Fix error handling. Remove memory
+ leak.
* readelf.c: Add ability to read archives.
(archive_file_offset): New variable.
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 25f5de6..ac1955e 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -10275,6 +10275,7 @@ process_archive (char *file_name, FILE *file)
char *longnames = NULL;
unsigned long longnames_size = 0;
size_t file_name_size;
+ int ret;
show_name = 1;
@@ -10326,6 +10327,7 @@ process_archive (char *file_name, FILE *file)
if (fread (longnames, longnames_size, 1, file) != 1)
{
+ free (longnames);
error(_("%s: failed to read string table\n"), file_name);
return 1;
}
@@ -10336,6 +10338,8 @@ process_archive (char *file_name, FILE *file)
got = fread (&arhdr, 1, sizeof arhdr, file);
if (got != sizeof arhdr)
{
+ free (longnames);
+
if (got == 0)
return 0;
@@ -10345,6 +10349,7 @@ process_archive (char *file_name, FILE *file)
}
file_name_size = strlen (file_name);
+ ret = 0;
while (1)
{
@@ -10360,7 +10365,8 @@ process_archive (char *file_name, FILE *file)
if (off >= longnames_size)
{
error (_("%s: invalid archive string table offset %lu\n"), off);
- return 1;
+ ret = 1;
+ break;
}
name = longnames + off;
@@ -10375,14 +10381,16 @@ process_archive (char *file_name, FILE *file)
if (nameend == NULL)
{
error (_("%s: bad archive file name\n"));
- return 1;
+ ret = 1;
+ break;
}
namealc = malloc (file_name_size + (nameend - name) + 3);
if (namealc == NULL)
{
error (_("Out of memory\n"));
- return 1;
+ ret = 1;
+ break;
}
memcpy (namealc, file_name, file_name_size);
@@ -10394,7 +10402,7 @@ process_archive (char *file_name, FILE *file)
archive_file_offset = ftell (file);
archive_file_size = strtoul (arhdr.ar_size, NULL, 10);
- process_object (namealc, file);
+ ret |= process_object (namealc, file);
free (namealc);
@@ -10405,24 +10413,26 @@ process_archive (char *file_name, FILE *file)
SEEK_SET) != 0)
{
error (_("%s: failed to seek to next archive header\n"), file_name);
- return 1;
+ ret = 1;
+ break;
}
got = fread (&arhdr, 1, sizeof arhdr, file);
if (got != sizeof arhdr)
{
if (got == 0)
- return 0;
+ break;
error (_("%s: failed to read archive header\n"), file_name);
- return 1;
+ ret = 1;
+ break;
}
}
if (longnames != 0)
free (longnames);
- return 0;
+ return ret;
}
static int