aboutsummaryrefslogtreecommitdiff
path: root/libcpp/files.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2013-03-06 17:18:40 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2013-03-06 17:18:40 +0100
commit28937f1196166ef33c303ff09f0d7f4936faec81 (patch)
tree81d6fae2161fe976ca587b7a58d10fda41f7e93b /libcpp/files.c
parentb681bb9507df9bf700eac671e3c999bd735b1939 (diff)
downloadgcc-28937f1196166ef33c303ff09f0d7f4936faec81.zip
gcc-28937f1196166ef33c303ff09f0d7f4936faec81.tar.gz
gcc-28937f1196166ef33c303ff09f0d7f4936faec81.tar.bz2
re PR middle-end/56461 (GCC is leaking lots of memory)
PR middle-end/56461 * internal.h (struct cpp_buffer): Add to_free field. (_cpp_pop_file_buffer): Add third argument. * files.c (_cpp_stack_file): Set buffer->to_free. (_cpp_pop_file_buffer): Add to_free argument. Free to_free if non-NULL, and if equal to file->buffer_start, also clear file->buffer{,_start,_valid}. * directives.c (_cpp_pop_buffer): Pass buffer->to_free to _cpp_pop_file_buffer. From-SVN: r196497
Diffstat (limited to 'libcpp/files.c')
-rw-r--r--libcpp/files.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/libcpp/files.c b/libcpp/files.c
index dae5526..5c5a0b9 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -894,6 +894,7 @@ _cpp_stack_file (cpp_reader *pfile, _cpp_file *file, bool import)
&& !CPP_OPTION (pfile, directives_only));
buffer->file = file;
buffer->sysp = sysp;
+ buffer->to_free = file->buffer_start;
/* Initialize controlling macro state. */
pfile->mi_valid = true;
@@ -1435,7 +1436,8 @@ cpp_push_default_include (cpp_reader *pfile, const char *fname)
/* Do appropriate cleanup when a file INC's buffer is popped off the
input stack. */
void
-_cpp_pop_file_buffer (cpp_reader *pfile, _cpp_file *file)
+_cpp_pop_file_buffer (cpp_reader *pfile, _cpp_file *file,
+ const unsigned char *to_free)
{
/* Record the inclusion-preventing macro, which could be NULL
meaning no controlling macro. */
@@ -1445,12 +1447,15 @@ _cpp_pop_file_buffer (cpp_reader *pfile, _cpp_file *file)
/* Invalidate control macros in the #including file. */
pfile->mi_valid = false;
- if (file->buffer_start)
+ if (to_free)
{
- free ((void *) file->buffer_start);
- file->buffer_start = NULL;
- file->buffer = NULL;
- file->buffer_valid = false;
+ if (to_free == file->buffer_start)
+ {
+ file->buffer_start = NULL;
+ file->buffer = NULL;
+ file->buffer_valid = false;
+ }
+ free ((void *) to_free);
}
}