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
This commit is contained in:
Jakub Jelinek 2013-03-06 17:18:40 +01:00 committed by Jakub Jelinek
parent b681bb9507
commit 28937f1196
4 changed files with 30 additions and 8 deletions

View File

@ -1,3 +1,15 @@
2013-03-06 Jakub Jelinek <jakub@redhat.com>
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.
2013-03-01 Jakub Jelinek <jakub@redhat.com> 2013-03-01 Jakub Jelinek <jakub@redhat.com>
PR middle-end/56461 PR middle-end/56461

View File

@ -2558,6 +2558,7 @@ _cpp_pop_buffer (cpp_reader *pfile)
cpp_buffer *buffer = pfile->buffer; cpp_buffer *buffer = pfile->buffer;
struct _cpp_file *inc = buffer->file; struct _cpp_file *inc = buffer->file;
struct if_stack *ifs; struct if_stack *ifs;
const unsigned char *to_free;
/* Walk back up the conditional stack till we reach its level at /* Walk back up the conditional stack till we reach its level at
entry to this file, issuing error messages. */ entry to this file, issuing error messages. */
@ -2571,6 +2572,7 @@ _cpp_pop_buffer (cpp_reader *pfile)
/* _cpp_do_file_change expects pfile->buffer to be the new one. */ /* _cpp_do_file_change expects pfile->buffer to be the new one. */
pfile->buffer = buffer->prev; pfile->buffer = buffer->prev;
to_free = buffer->to_free;
free (buffer->notes); free (buffer->notes);
/* Free the buffer object now; we may want to push a new buffer /* Free the buffer object now; we may want to push a new buffer
@ -2579,7 +2581,7 @@ _cpp_pop_buffer (cpp_reader *pfile)
if (inc) if (inc)
{ {
_cpp_pop_file_buffer (pfile, inc); _cpp_pop_file_buffer (pfile, inc, to_free);
_cpp_do_file_change (pfile, LC_LEAVE, 0, 0, 0); _cpp_do_file_change (pfile, LC_LEAVE, 0, 0, 0);
} }

View File

@ -894,6 +894,7 @@ _cpp_stack_file (cpp_reader *pfile, _cpp_file *file, bool import)
&& !CPP_OPTION (pfile, directives_only)); && !CPP_OPTION (pfile, directives_only));
buffer->file = file; buffer->file = file;
buffer->sysp = sysp; buffer->sysp = sysp;
buffer->to_free = file->buffer_start;
/* Initialize controlling macro state. */ /* Initialize controlling macro state. */
pfile->mi_valid = true; 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 /* Do appropriate cleanup when a file INC's buffer is popped off the
input stack. */ input stack. */
void 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 /* Record the inclusion-preventing macro, which could be NULL
meaning no controlling macro. */ meaning no controlling macro. */
@ -1445,13 +1447,16 @@ _cpp_pop_file_buffer (cpp_reader *pfile, _cpp_file *file)
/* Invalidate control macros in the #including file. */ /* Invalidate control macros in the #including file. */
pfile->mi_valid = false; pfile->mi_valid = false;
if (file->buffer_start) if (to_free)
{
if (to_free == file->buffer_start)
{ {
free ((void *) file->buffer_start);
file->buffer_start = NULL; file->buffer_start = NULL;
file->buffer = NULL; file->buffer = NULL;
file->buffer_valid = false; file->buffer_valid = false;
} }
free ((void *) to_free);
}
} }
/* Return the file name associated with FILE. */ /* Return the file name associated with FILE. */

View File

@ -301,6 +301,8 @@ struct cpp_buffer
const unsigned char *buf; /* Entire character buffer. */ const unsigned char *buf; /* Entire character buffer. */
const unsigned char *rlimit; /* Writable byte at end of file. */ const unsigned char *rlimit; /* Writable byte at end of file. */
const unsigned char *to_free; /* Pointer that should be freed when
popping the buffer. */
_cpp_line_note *notes; /* Array of notes. */ _cpp_line_note *notes; /* Array of notes. */
unsigned int cur_note; /* Next note to process. */ unsigned int cur_note; /* Next note to process. */
@ -635,7 +637,8 @@ extern int _cpp_compare_file_date (cpp_reader *, const char *, int);
extern void _cpp_report_missing_guards (cpp_reader *); extern void _cpp_report_missing_guards (cpp_reader *);
extern void _cpp_init_files (cpp_reader *); extern void _cpp_init_files (cpp_reader *);
extern void _cpp_cleanup_files (cpp_reader *); extern void _cpp_cleanup_files (cpp_reader *);
extern void _cpp_pop_file_buffer (cpp_reader *, struct _cpp_file *); extern void _cpp_pop_file_buffer (cpp_reader *, struct _cpp_file *,
const unsigned char *);
extern bool _cpp_save_file_entries (cpp_reader *pfile, FILE *f); extern bool _cpp_save_file_entries (cpp_reader *pfile, FILE *f);
extern bool _cpp_read_file_entries (cpp_reader *, FILE *); extern bool _cpp_read_file_entries (cpp_reader *, FILE *);
extern const char *_cpp_get_file_name (_cpp_file *); extern const char *_cpp_get_file_name (_cpp_file *);