cpplib: Plug more memory leaks.

Neil Booth NeilB@earthling.net
Sun Aug 13 05:28:00 GMT 2000


This patch closes more memory leaks in cpplib.  I don't know of any
remaining ones.

Neil.

	* cppinit.c (cpp_cleanup): Free include dir chains.
	* cpplib.c (do_undef): Let _cpp_free_definition make the node void.
	(do_unassert): Free the assert with _cpp_free_definition.
	* cppmacro.c (_cpp_free_definition): Free memory allocated for
	assertions.  Make the node a T_VOID node.

Index: cppinit.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cppinit.c,v
retrieving revision 1.100
diff -u -p -r1.100 cppinit.c
@@ -463,6 +447,8 @@ void
 cpp_cleanup (pfile)
      cpp_reader *pfile;
 {
+  struct file_name_list *dir, *next;
+
   while (CPP_BUFFER (pfile) != NULL)
     cpp_pop_buffer (pfile);
 
@@ -476,6 +462,13 @@ cpp_cleanup (pfile)
   _cpp_cleanup_includes (pfile);
   _cpp_cleanup_stacks (pfile);
   _cpp_cleanup_macros (pfile);
+
+  for (dir = CPP_OPTION (pfile, quote_include); dir; dir = next)
+    {
+      next = dir->next;
+      free (dir->name);
+      free (dir);
+    }
 }
 
 
Index: cpplib.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpplib.c,v
retrieving revision 1.197
diff -u -p -r1.197 cpplib.c
--- cpplib.c	2000/08/09 19:41:12	1.197
+++ cpplib.c	2000/08/13 12:20:35
@@ -298,7 +298,6 @@ do_undef (pfile)
 	cpp_warning (pfile, "undefining \"%s\"", node->name);
 
       _cpp_free_definition (node);
-      node->type = T_VOID;
     }
 }
 
@@ -1369,14 +1368,7 @@ do_unassert (pfile)
 		node->type = T_VOID;
 	    }
 	  else
-	    {
-	      for (temp = node->value.answers; temp; temp = next)
-		{
-		  next = temp->next;
-		  FREE_ANSWER (temp);
-		}
-	      node->type = T_VOID;
-	    }
+	    _cpp_free_definition (node);
 	}
 
       if (answer)
Index: cppmacro.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cppmacro.c,v
retrieving revision 1.8
diff -u -p -r1.8 cppmacro.c
--- cppmacro.c	2000/08/09 19:41:12	1.8
+++ cppmacro.c	2000/08/13 12:20:40
@@ -404,6 +404,18 @@ _cpp_free_definition (h)
 {
   if (h->type == T_MACRO)
     free ((PTR) h->value.expansion);
+  else if (h->type == T_ASSERTION)
+    {
+      struct answer *temp, *next;
+
+      for (temp = h->value.answers; temp; temp = next)
+	{
+	  next = temp->next;
+	  FREE_ANSWER (temp);
+	}
+    }
+
+  h->type = T_VOID;
   h->value.expansion = NULL;
 }
 


More information about the Gcc-patches mailing list