This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: preprocessor/556: cpplib uses freed file descriptors


This fixes this bug.  I'm not really sure what semantics Zack had in
mind for file caching, so I cannot claim this is the "right (tm)" fix.

The code was assuming that a file found in the splay tree, that had
been purged from cache, had a valid file descriptor.  This isn't the
case, so I faced the choice of removing purged caches from the splay
tree, or adding a bunch of checks.  I opted for the former.

If this completes a bootstrap / testsuite cycle, I'll commit it and
the testcase.

Neil.

	* cppfiles.c (_cpp_pop_file_buffer): Remove purged caches
	from the splay tree to force a re-open if necessary later.
	* gcc.gd/cpp/mi4.c: A testcase.

Index: cppfiles.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cppfiles.c,v
retrieving revision 1.81
diff -u -p -r1.81 cppfiles.c
--- cppfiles.c	2000/09/19 17:28:46	1.81
+++ cppfiles.c	2000/09/20 06:10:27
@@ -735,7 +735,8 @@ _cpp_pop_file_buffer (pfile, buf)
 
   inc->refcnt--;
   if (inc->refcnt == 0 && DO_NOT_REREAD (inc))
-    purge_cache (inc);
+    splay_tree_remove (pfile->all_include_files,
+		       (splay_tree_key) inc->name);
 }
 
 /* The file_name_map structure holds a mapping of file names for a
Index: testsuite/gcc.dg/cpp/mi4.c
===================================================================
RCS file: mi4.c
diff -N mi4.c
--- /dev/null	Tue May  5 13:32:27 1998
+++ mi4.c	Tue Sep 19 23:10:41 2000
@@ -0,0 +1,10 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.  */
+
+/* { dg-do preprocess } */
+
+/* Undefining a macro guard and re-including the file used to confuse
+   file caching in cppfiles.c, and attempt to open a bad fd.  */
+
+#include "mi1c.h"
+#undef CPP_MIC_H
+#include "mi1c.h"

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]