summaryrefslogtreecommitdiff
path: root/libcpp/mkdeps.c
diff options
context:
space:
mode:
authorTobias Burnus <burnus@net-b.de>2012-10-15 22:08:57 +0200
committerTobias Burnus <burnus@gcc.gnu.org>2012-10-15 22:08:57 +0200
commit55e7f90769fbc29ce4e156d33c63298497acceb7 (patch)
tree9638e29aa7f7e52938c01390081a134c642b7a02 /libcpp/mkdeps.c
parent95bf35bd2566026f8337185dff6633358b3bbb7f (diff)
downloadgcc-55e7f90769fbc29ce4e156d33c63298497acceb7.tar.gz
files.c (read_file_guts, [...]): Free memory before returning.
2012-10-15 Tobias Burnus <burnus@net-b.de> * files.c (read_file_guts, _cpp_save_file_entries): Free memory before returning. * lex.c (warn_about_normalization): Ditto. * mkdeps.c (deps_save): Ditto. * pch.c (cpp_valid_state): Ditto. From-SVN: r192474
Diffstat (limited to 'libcpp/mkdeps.c')
-rw-r--r--libcpp/mkdeps.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/libcpp/mkdeps.c b/libcpp/mkdeps.c
index af11ac3a6e3..b57681392a6 100644
--- a/libcpp/mkdeps.c
+++ b/libcpp/mkdeps.c
@@ -399,25 +399,33 @@ deps_restore (struct deps *deps, FILE *fd, const char *self)
unsigned int i, count;
size_t num_to_read;
size_t buf_size = 512;
- char *buf = XNEWVEC (char, buf_size);
+ char *buf;
/* Number of dependences. */
if (fread (&count, 1, sizeof (count), fd) != sizeof (count))
return -1;
+ buf = XNEWVEC (char, buf_size);
+
/* The length of each dependence string, followed by the string. */
for (i = 0; i < count; i++)
{
/* Read in # bytes in string. */
if (fread (&num_to_read, 1, sizeof (size_t), fd) != sizeof (size_t))
- return -1;
+ {
+ free (buf);
+ return -1;
+ }
if (buf_size < num_to_read + 1)
{
buf_size = num_to_read + 1 + 127;
buf = XRESIZEVEC (char, buf, buf_size);
}
if (fread (buf, 1, num_to_read, fd) != num_to_read)
- return -1;
+ {
+ free (buf);
+ return -1;
+ }
buf[num_to_read] = '\0';
/* Generate makefile dependencies from .pch if -nopch-deps. */