texinfo-commits
[Top][All Lists]
Advanced

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

[8345] parsetexi multitable prototypes fix memory leak


From: gavinsmith0123
Subject: [8345] parsetexi multitable prototypes fix memory leak
Date: Fri, 19 Oct 2018 18:15:39 -0400 (EDT)

Revision: 8345
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=8345
Author:   gavin
Date:     2018-10-19 18:15:39 -0400 (Fri, 19 Oct 2018)
Log Message:
-----------
parsetexi multitable prototypes fix memory leak

Modified Paths:
--------------
    trunk/tp/Texinfo/XS/parsetexi/api.c
    trunk/tp/Texinfo/XS/parsetexi/end_line.c
    trunk/tp/Texinfo/XS/parsetexi/extra.c
    trunk/tp/Texinfo/XS/parsetexi/parser.h
    trunk/tp/Texinfo/XS/parsetexi/tree.c
    trunk/tp/Texinfo/XS/parsetexi/tree_types.h

Modified: trunk/tp/Texinfo/XS/parsetexi/api.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/api.c 2018-10-19 20:58:06 UTC (rev 8344)
+++ trunk/tp/Texinfo/XS/parsetexi/api.c 2018-10-19 22:15:39 UTC (rev 8345)
@@ -359,6 +359,7 @@
               STORE(newRV_inc ((SV *)f->hv));
               break;
             case extra_contents:
+            case extra_contents_oot:
               {
               int j;
               if (f)

Modified: trunk/tp/Texinfo/XS/parsetexi/end_line.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/end_line.c    2018-10-19 20:58:06 UTC (rev 
8344)
+++ trunk/tp/Texinfo/XS/parsetexi/end_line.c    2018-10-19 22:15:39 UTC (rev 
8345)
@@ -1050,9 +1050,6 @@
             }
           else // 2913
             {
-              // Perl code was sceptical whether we could get here,
-              // but we got here from t/21multitable.t on 2015.11.30.
-              // FIXME: put an abort() here and run the tests
               if (!e->cmd)
                 {
                   command_warn (current, "unexpected argument on @%s line:",
@@ -1059,28 +1056,19 @@
                                 command_name(current->cmd));
                   // TODO: Convert argument to Texinfo
                 }
-              else if (e->cmd != CM_c && e->cmd != CM_comment)
-                {
-                  add_to_contents_as_array (prototypes, e);
-                }
             }
         }
 
       {
-      char *s; /* FIXME: could just use prototypes instead */
       int max_columns = prototypes->contents.number;
-      asprintf (&s, "%d", max_columns);
-      add_extra_string (current->parent, "max_columns", s);
+      add_extra_integer (current->parent, "max_columns", max_columns);
       if (max_columns == 0)
         command_warn (current->parent, "empty multitable");
       }
-      add_extra_contents (current->parent, "prototypes", prototypes);
-      isolate_last_space (current);
+      add_extra_contents_oot (current->parent, "prototypes", prototypes);
+      /* See code in destroy_element for how prototypes is deallocated. */
     }
-  else
-    {
-      isolate_last_space (current);
-    }
+  isolate_last_space (current);
 
   current = current->parent; //2965
   if (counter_value (&count_remaining_args, current) != -1)

Modified: trunk/tp/Texinfo/XS/parsetexi/extra.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/extra.c       2018-10-19 20:58:06 UTC (rev 
8344)
+++ trunk/tp/Texinfo/XS/parsetexi/extra.c       2018-10-19 22:15:39 UTC (rev 
8345)
@@ -68,6 +68,13 @@
   add_extra_key (e, key, value, extra_contents);
 }
 
+/* Like add_extra_contents but all of the contents are out-of-tree. */
+void
+add_extra_contents_oot (ELEMENT *e, char *key, ELEMENT *value)
+{
+  add_extra_key (e, key, value, extra_contents_oot);
+}
+
 /* An array of content arrays. */
 void
 add_extra_contents_array (ELEMENT *e, char *key, ELEMENT *value)

Modified: trunk/tp/Texinfo/XS/parsetexi/parser.h
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/parser.h      2018-10-19 20:58:06 UTC (rev 
8344)
+++ trunk/tp/Texinfo/XS/parsetexi/parser.h      2018-10-19 22:15:39 UTC (rev 
8345)
@@ -100,6 +100,7 @@
 void add_extra_element (ELEMENT *e, char *key, ELEMENT *value);
 void add_extra_element_oot (ELEMENT *e, char *key, ELEMENT *value);
 void add_extra_contents (ELEMENT *e, char *key, ELEMENT *value);
+void add_extra_contents_oot (ELEMENT *e, char *key, ELEMENT *value);
 void add_extra_contents_array (ELEMENT *e, char *key, ELEMENT *value);
 void add_extra_text (ELEMENT *e, char *key, ELEMENT *value);
 void add_extra_index_entry (ELEMENT *e, char *key, INDEX_ENTRY_REF *value);

Modified: trunk/tp/Texinfo/XS/parsetexi/tree.c
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/tree.c        2018-10-19 20:58:06 UTC (rev 
8344)
+++ trunk/tp/Texinfo/XS/parsetexi/tree.c        2018-10-19 22:15:39 UTC (rev 
8345)
@@ -70,6 +70,24 @@
           if (e->extra[i].value)
             destroy_element ((ELEMENT *) e->extra[i].value);
           break;
+        case extra_contents_oot:
+          {
+            /* Only used for 'prototypes' */
+            /* Destroy each element in the array, but not any children
+               of each element. */
+            int j;
+            ELEMENT *array = e->extra[i].value;
+            for (j = 0 ; j < array->contents.number; j++)
+              {
+                if (array->contents.list[j])
+                  {
+                    free (array->contents.list[j]->text.text);
+                    free (array->contents.list[j]);
+                  }
+              }
+            destroy_element (array);
+            break;
+          }
         case extra_contents_array:
           {
             int j;

Modified: trunk/tp/Texinfo/XS/parsetexi/tree_types.h
===================================================================
--- trunk/tp/Texinfo/XS/parsetexi/tree_types.h  2018-10-19 20:58:06 UTC (rev 
8344)
+++ trunk/tp/Texinfo/XS/parsetexi/tree_types.h  2018-10-19 22:15:39 UTC (rev 
8345)
@@ -28,6 +28,7 @@
     extra_element,
     extra_element_oot,
     extra_contents,
+    extra_contents_oot,
     extra_contents_array,
     extra_text,
     extra_index_entry,




reply via email to

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