From 15fc692a8e33d3b3bf82e8c9ae7f4572baac6e63 Mon Sep 17 00:00:00 2001 From: burnus Date: Mon, 15 Oct 2012 20:08:57 +0000 Subject: [PATCH] 2012-10-15 Tobias Burnus * 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@192474 138bc75d-0d04-0410-961f-82ee72b054a4 --- libcpp/ChangeLog | 8 ++++++++ libcpp/files.c | 2 ++ libcpp/lex.c | 1 + libcpp/mkdeps.c | 14 +++++++++++--- libcpp/pch.c | 1 - 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 957b216..fdc151c 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,11 @@ +2012-10-15 Tobias Burnus + + * 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. + 2012-10-04 Florian Weimer * directives.c (do_pragma_warning_or_error): New. diff --git a/libcpp/files.c b/libcpp/files.c index 5b3a37b..6fc24e2 100644 --- a/libcpp/files.c +++ b/libcpp/files.c @@ -671,6 +671,7 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file) if (count < 0) { cpp_errno (pfile, CPP_DL_ERROR, file->path); + free (buf); return false; } @@ -1759,6 +1760,7 @@ _cpp_save_file_entries (cpp_reader *pfile, FILE *fp) if (!open_file (f)) { open_file_failed (pfile, f, 0); + free (result); return false; } ff = fdopen (f->fd, "rb"); diff --git a/libcpp/lex.c b/libcpp/lex.c index ab904db..23809bc 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -1094,6 +1094,7 @@ warn_about_normalization (cpp_reader *pfile, else cpp_warning_with_line (pfile, CPP_W_NORMALIZE, token->src_loc, 0, "`%.*s' is not in NFC", (int) sz, buf); + free (buf); } } diff --git a/libcpp/mkdeps.c b/libcpp/mkdeps.c index af11ac3..b576813 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. */ diff --git a/libcpp/pch.c b/libcpp/pch.c index d278f14..001bf3f 100644 --- a/libcpp/pch.c +++ b/libcpp/pch.c @@ -710,7 +710,6 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd) error: cpp_errno (r, CPP_DL_ERROR, "while reading precompiled header"); - return -1; fail: free (namebuf); -- 2.7.4