Commit 55e7f907 by Tobias Burnus Committed by Tobias Burnus

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
parent 95bf35bd
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.
2012-10-04 Florian Weimer <fweimer@redhat.com> 2012-10-04 Florian Weimer <fweimer@redhat.com>
* directives.c (do_pragma_warning_or_error): New. * directives.c (do_pragma_warning_or_error): New.
......
...@@ -671,6 +671,7 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file) ...@@ -671,6 +671,7 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file)
if (count < 0) if (count < 0)
{ {
cpp_errno (pfile, CPP_DL_ERROR, file->path); cpp_errno (pfile, CPP_DL_ERROR, file->path);
free (buf);
return false; return false;
} }
...@@ -1759,6 +1760,7 @@ _cpp_save_file_entries (cpp_reader *pfile, FILE *fp) ...@@ -1759,6 +1760,7 @@ _cpp_save_file_entries (cpp_reader *pfile, FILE *fp)
if (!open_file (f)) if (!open_file (f))
{ {
open_file_failed (pfile, f, 0); open_file_failed (pfile, f, 0);
free (result);
return false; return false;
} }
ff = fdopen (f->fd, "rb"); ff = fdopen (f->fd, "rb");
......
...@@ -1094,6 +1094,7 @@ warn_about_normalization (cpp_reader *pfile, ...@@ -1094,6 +1094,7 @@ warn_about_normalization (cpp_reader *pfile,
else else
cpp_warning_with_line (pfile, CPP_W_NORMALIZE, token->src_loc, 0, cpp_warning_with_line (pfile, CPP_W_NORMALIZE, token->src_loc, 0,
"`%.*s' is not in NFC", (int) sz, buf); "`%.*s' is not in NFC", (int) sz, buf);
free (buf);
} }
} }
......
...@@ -399,25 +399,33 @@ deps_restore (struct deps *deps, FILE *fd, const char *self) ...@@ -399,25 +399,33 @@ deps_restore (struct deps *deps, FILE *fd, const char *self)
unsigned int i, count; unsigned int i, count;
size_t num_to_read; size_t num_to_read;
size_t buf_size = 512; size_t buf_size = 512;
char *buf = XNEWVEC (char, buf_size); char *buf;
/* Number of dependences. */ /* Number of dependences. */
if (fread (&count, 1, sizeof (count), fd) != sizeof (count)) if (fread (&count, 1, sizeof (count), fd) != sizeof (count))
return -1; return -1;
buf = XNEWVEC (char, buf_size);
/* The length of each dependence string, followed by the string. */ /* The length of each dependence string, followed by the string. */
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
/* Read in # bytes in string. */ /* Read in # bytes in string. */
if (fread (&num_to_read, 1, sizeof (size_t), fd) != sizeof (size_t)) 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) if (buf_size < num_to_read + 1)
{ {
buf_size = num_to_read + 1 + 127; buf_size = num_to_read + 1 + 127;
buf = XRESIZEVEC (char, buf, buf_size); buf = XRESIZEVEC (char, buf, buf_size);
} }
if (fread (buf, 1, num_to_read, fd) != num_to_read) if (fread (buf, 1, num_to_read, fd) != num_to_read)
return -1; {
free (buf);
return -1;
}
buf[num_to_read] = '\0'; buf[num_to_read] = '\0';
/* Generate makefile dependencies from .pch if -nopch-deps. */ /* Generate makefile dependencies from .pch if -nopch-deps. */
......
...@@ -710,7 +710,6 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd) ...@@ -710,7 +710,6 @@ cpp_valid_state (cpp_reader *r, const char *name, int fd)
error: error:
cpp_errno (r, CPP_DL_ERROR, "while reading precompiled header"); cpp_errno (r, CPP_DL_ERROR, "while reading precompiled header");
return -1;
fail: fail:
free (namebuf); free (namebuf);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment