This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch for cpplib clients to free resources
- To: gcc-patches at gcc dot gnu dot org
- Subject: Patch for cpplib clients to free resources
- From: Neil Booth <neil at daikokuya dot demon dot co dot uk>
- Date: Sun, 14 Jan 2001 20:27:22 +0000
This fixes a rather large memory leak in all cpplib clients.
This is my last patch before the slush, after which I'll concentrate
on performance enhancements (since cpplib has no known bugs :-))
Bootstrapped i586 Linux.
Neil.
* c-parse.in (finish_parse): Get error count from cpp_destroy.
* cp/lex.c (finish_parse): Similarly.
* cppinit.c (cpp_cleanup): Rename cpp_destroy for clarity.
Return the number of errors encountered.
* cpplib.h (cpp_cleanup): Rename cpp_destroy, return int.
* cppmain.c (main): Update to call cpp_destroy.
* fix-header.c (read_scan_file): Update to call cpp_destroy.
Index: c-parse.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-parse.in,v
retrieving revision 1.78
diff -u -p -r1.78 c-parse.in
--- c-parse.in 2001/01/13 14:23:03 1.78
+++ c-parse.in 2001/01/14 17:27:26
@@ -3161,7 +3161,7 @@ void
finish_parse ()
{
cpp_finish (parse_in);
- errorcount += cpp_errors (parse_in);
+ errorcount += cpp_destroy (parse_in);
}
#define NAME(type) cpp_type2name (type)
Index: cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.141
diff -u -p -r1.141 cppinit.c
--- cppinit.c 2001/01/13 01:00:01 1.141
+++ cppinit.c 2001/01/14 17:27:29
@@ -557,12 +557,13 @@ cpp_create_reader (lang)
return pfile;
}
-/* Free resources used by PFILE.
- This is the cpp_reader 'finalizer' or 'destructor' (in C++ terminology). */
-void
-cpp_cleanup (pfile)
+/* Free resources used by PFILE. Accessing PFILE after this function
+ returns leads to undefined behaviour. */
+int
+cpp_destroy (pfile)
cpp_reader *pfile;
{
+ int result;
struct file_name_list *dir, *dirn;
cpp_context *context, *contextn;
@@ -600,6 +601,11 @@ cpp_cleanup (pfile)
contextn = context->next;
free (context);
}
+
+ result = pfile->errors;
+ free (pfile);
+
+ return result;
}
Index: cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.160
diff -u -p -r1.160 cpplib.h
--- cpplib.h 2001/01/13 14:32:59 1.160
+++ cpplib.h 2001/01/14 17:27:50
@@ -494,6 +494,10 @@ struct cpp_hashnode
/* Call this first to get a handle to pass to other functions. */
extern cpp_reader *cpp_create_reader PARAMS ((enum c_lang));
+/* Call this to release the handle. Any use of the handle after this
+ function returns is invalid. Returns cpp_errors (pfile). */
+extern int cpp_destroy PARAMS ((cpp_reader *));
+
/* Call these to get pointers to the options and callback structures
for a given reader. These pointers are good until you call
cpp_finish on that reader. You can either edit the callbacks
@@ -529,7 +533,6 @@ extern void cpp_register_pragma_space PA
extern int cpp_start_read PARAMS ((cpp_reader *, const char *));
extern void cpp_finish PARAMS ((cpp_reader *));
-extern void cpp_cleanup PARAMS ((cpp_reader *));
extern int cpp_avoid_paste PARAMS ((cpp_reader *, const cpp_token *,
const cpp_token *));
extern enum cpp_ttype cpp_can_paste PARAMS ((cpp_reader *, const cpp_token *,
Index: cppmain.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmain.c,v
retrieving revision 1.57
diff -u -p -r1.57 cppmain.c
--- cppmain.c 2001/01/14 16:44:50 1.57
+++ cppmain.c 2001/01/14 17:27:50
@@ -79,10 +79,7 @@ main (argc, argv)
do_preprocessing (argc, argv);
- /* Reader destructor. */
- cpp_cleanup (pfile);
-
- if (cpp_errors (pfile))
+ if (cpp_destroy (pfile))
return FATAL_EXIT_CODE;
return SUCCESS_EXIT_CODE;
Index: fix-header.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fix-header.c,v
retrieving revision 1.63
diff -u -p -r1.63 fix-header.c
--- fix-header.c 2001/01/13 01:13:35 1.63
+++ fix-header.c 2001/01/14 17:27:50
@@ -635,11 +635,11 @@ read_scan_file (in_fname, argc, argv)
if (i < argc && ! CPP_FATAL_ERRORS (scan_in))
cpp_fatal (scan_in, "Invalid option `%s'", argv[i]);
cpp_post_options (scan_in);
- if (CPP_FATAL_ERRORS (scan_in))
- exit (FATAL_EXIT_CODE);
-
- if (! cpp_start_read (scan_in, in_fname))
- exit (FATAL_EXIT_CODE);
+ if (CPP_FATAL_ERRORS (scan_in) || ! cpp_start_read (scan_in, in_fname))
+ {
+ cpp_destroy (scan_in);
+ exit (FATAL_EXIT_CODE);
+ }
/* We are scanning a system header, so mark it as such. */
cpp_make_system_header (scan_in, 1, 0);
@@ -697,6 +697,8 @@ read_scan_file (in_fname, argc, argv)
}
}
}
+
+ cpp_destroy (scan_in);
if (required_unseen_count + partial_count + required_other
#if ADD_MISSING_EXTERN_C
Index: cp/lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/lex.c,v
retrieving revision 1.234
diff -u -p -r1.234 lex.c
--- lex.c 2001/01/13 14:23:04 1.234
+++ lex.c 2001/01/14 17:27:55
@@ -755,7 +755,7 @@ void
finish_parse ()
{
cpp_finish (parse_in);
- errorcount += cpp_errors (parse_in);
+ errorcount += cpp_destroy (parse_in);
}
inline void