bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bison-1_29-branch] mem.patch


From: marc-alexandre autret
Subject: [bison-1_29-branch] mem.patch
Date: Sat, 22 Sep 2001 19:53:40 +0000 (GMT)

Hi,

An idea of patch to avoid memory leaks...

Index: ChangeLog
===================================================================
RCS file: /cvsroot/bison/bison/ChangeLog,v
retrieving revision 1.173.2.45
diff -u -r1.173.2.45 ChangeLog
--- ChangeLog   2001/09/22 16:56:36     1.173.2.45
+++ ChangeLog   2001/09/22 17:54:23
@@ -1,3 +1,9 @@
+2001-09-22  Marc Autret  <address@hidden>
+
+       * src/files.c (free_obsatcks): New.
+       (obstack_save): Add argument EXT.
+       (output_files): Use them.
+
 2001-09-22  Akim Demaille  <address@hidden>
 
        * configure.in: Bump to 1.29b.
Index: src/files.c
===================================================================
RCS file: /cvsroot/bison/bison/src/files.c,v
retrieving revision 1.51.2.2
diff -u -r1.51.2.2 files.c
--- src/files.c 2001/09/17 23:00:01     1.51.2.2
+++ src/files.c 2001/09/22 17:54:23
@@ -153,16 +153,23 @@
   return result;
 }
 
-/*--------------------------------------------------.
-| Save the content of the obstack OBS in FILENAME.  |
-`--------------------------------------------------*/
+/*-------------------------------------------------------.
+| Save the content of the obstack OBS in FILENAME##EXT.  |
+`-------------------------------------------------------*/
 
 static void
-obstack_save (struct obstack *obs, const char *filename)
+obstack_save (struct obstack *obs, const char *filename, const char *ext)
 {
-  FILE *out = xfopen (filename, "w");
   size_t size = obstack_object_size (obs);
+  char *fullname = NULL; 
+  FILE *out;
+  
+  fullname = stringappend (filename, ext);
+  
+  out = xfopen (fullname, "w");
+  
   fwrite (obstack_finish (obs), 1, size, out);
+  free (fullname);
   xfclose (out);
 }
 
@@ -408,6 +415,18 @@
 }
 
 
+/* Free obstacks initialized above!  */
+static void
+free_obsatcks ()
+{
+  obstack_free (&action_obstack, NULL);
+  obstack_free (&attrs_obstack, NULL);
+  obstack_free (&table_obstack, NULL);
+  obstack_free (&defines_obstack, NULL);
+  obstack_free (&guard_obstack, NULL);
+  obstack_free (&output_obstack, NULL);
+  obstack_free (&graph_obstack, NULL);
+}
 
 /*-----------------------------------------------------.
 | Close the open files, produce all the output files.  |
@@ -435,9 +454,9 @@
 
   /* Output the main file.  */
   if (spec_outfile)
-    obstack_save (&table_obstack, spec_outfile);
+    obstack_save (&table_obstack, spec_outfile, "");
   else
-    obstack_save (&table_obstack, stringappend (base_name, src_extension));
+    obstack_save (&table_obstack, base_name, src_extension);
 
   /* Output the header file if wanted. */
   if (defines_flag)
@@ -445,7 +464,7 @@
 
   /* If we output only the table, dump the actions in ACTFILE. */
   if (no_parser_flag)
-    obstack_save (&action_obstack, stringappend (short_base_name, ".act"));
+    obstack_save (&action_obstack, short_base_name, ".act");
 
   /* If we produced a semantic parser ATTRS_OBSTACK must be dumped
      into its own file, ATTTRSFILE.  */
@@ -453,20 +472,21 @@
     {
       char *temp_name;
 
-      obstack_save (&attrs_obstack, attrsfile);
+      obstack_save (&attrs_obstack, attrsfile, "");
       temp_name = stringappend (short_base_name, EXT_GUARD_C);
 #ifndef MSDOS
       temp_name = stringappend (temp_name, src_extension);
 #endif /* MSDOS */
-      obstack_save (&guard_obstack, temp_name);
+      obstack_save (&guard_obstack, temp_name, "");
     }
 
   if (verbose_flag)
     /* We used to use just .out if spec_name_prefix (-p) was used, but
        that conflicts with Posix.  */
-    obstack_save (&output_obstack,
-                 stringappend (short_base_name, EXT_OUTPUT));
+    obstack_save (&output_obstack, short_base_name, EXT_OUTPUT);
 
   if (graph_flag)
-    obstack_save (&graph_obstack, spec_graph_file);
+    obstack_save (&graph_obstack, spec_graph_file, "");
+
+  free_obsatcks ();
 }


-- 
Autret Marc (address@hidden)
Eleve Ingenieur en Informatique.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]