[1/2] Add free_cpp_dirs()

Message ID 20211105211718.2261686-2-rep.dot.nop@gmail.com
State New
Headers
Series incpath, Fortran: Fix memory leak in gfc_add_include_path |

Commit Message

Bernhard Reutner-Fischer Nov. 5, 2021, 9:17 p.m. UTC
  From: Bernhard Reutner-Fischer <aldot@gcc.gnu.org>

gcc/ChangeLog:

	* incpath.c (free_cpp_dirs): New function.
	* incpath.h (free_cpp_dirs): Ditto.

---
This adds a helper to allow the fortran FE to free it's include dirs.

Bootstrapped and regtested without new regressions on x86_64-unknown-linux.
Ok for trunk?
---
 gcc/incpath.c | 13 +++++++++++++
 gcc/incpath.h |  1 +
 2 files changed, 14 insertions(+)
  

Patch

diff --git a/gcc/incpath.c b/gcc/incpath.c
index 52dbb806b1b..de77a56062c 100644
--- a/gcc/incpath.c
+++ b/gcc/incpath.c
@@ -513,6 +513,19 @@  get_added_cpp_dirs (incpath_kind chain)
   return heads[chain];
 }
 
+/* Free all cpp dirs.  */
+void
+free_cpp_dirs (void)
+{
+  struct cpp_dir **pcur, *cur;
+  for (pcur = &heads[INC_QUOTE]; *pcur;)
+    {
+      cur = *pcur;
+      *pcur = cur->next;
+      free_path (cur, REASON_QUIET);
+    }
+}
+
 #if !(defined TARGET_EXTRA_INCLUDES) || !(defined TARGET_EXTRA_PRE_INCLUDES)
 static void hook_void_charptr_charptr_int (const char *sysroot ATTRIBUTE_UNUSED,
 					   const char *iprefix ATTRIBUTE_UNUSED,
diff --git a/gcc/incpath.h b/gcc/incpath.h
index 2a4a314d7f9..4bf878b4e74 100644
--- a/gcc/incpath.h
+++ b/gcc/incpath.h
@@ -34,6 +34,7 @@  extern void register_include_chains (cpp_reader *, const char *,
 				     int, int, int);
 extern void add_cpp_dir_path (struct cpp_dir *, incpath_kind);
 extern struct cpp_dir *get_added_cpp_dirs (incpath_kind);
+extern void free_cpp_dirs(void);
 
 struct target_c_incpath_s {
   /* Do extra includes processing.  STDINC is false iff -nostdinc was given.  */