texinfo-commits
[Top][All Lists]
Advanced

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

[5700] some memory leaks


From: Gavin D. Smith
Subject: [5700] some memory leaks
Date: Sat, 05 Jul 2014 18:49:04 +0000

Revision: 5700
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5700
Author:   gavin
Date:     2014-07-05 18:49:01 +0000 (Sat, 05 Jul 2014)
Log Message:
-----------
some memory leaks

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/dir.c
    trunk/info/footnotes.c
    trunk/info/info.c
    trunk/info/nodes.c
    trunk/info/session.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-07-05 16:26:11 UTC (rev 5699)
+++ trunk/ChangeLog     2014-07-05 18:49:01 UTC (rev 5700)
@@ -1,5 +1,20 @@
 2014-07-05  Gavin Smith  <address@hidden>
 
+       * info/dir.c (dir_entry_of_infodir)
+       * info/footnotes.c (make_footnotes_node) 
+       * info/session.c (info_intuit_options_node): Free return value of
+       info_get_node.
+
+       * info/info.c (add_initial_nodes): Free a string.
+
+       * info/session.c (info_goto_invocation_node): Don't use
+       info_error_was_printed to check for an error.
+       (dump_node_to_stream): Free NODE object at more exit points from
+       function.
+       (info_search_internal): Free variable before exiting function.
+
+2014-07-05  Gavin Smith  <address@hidden>
+
        * info/session.c (node_printed_rep): Keep pointer to storage to
        returned string in static pointer to avoid memory leaks by callers.
        (info_menu_sequence): Don't clear echo area if there was an error

Modified: trunk/info/dir.c
===================================================================
--- trunk/info/dir.c    2014-07-05 16:26:11 UTC (rev 5699)
+++ trunk/info/dir.c    2014-07-05 18:49:01 UTC (rev 5700)
@@ -285,6 +285,7 @@
       dir_node = info_get_node (dir_fullpath, "Top");
       free (dir_fullpath);
       entry = info_get_menu_entry_by_label (dir_node, label, 1);
+      free (dir_node);
       if (!entry)
         continue;
 

Modified: trunk/info/footnotes.c
===================================================================
--- trunk/info/footnotes.c      2014-07-05 16:26:11 UTC (rev 5699)
+++ trunk/info/footnotes.c      2014-07-05 18:49:01 UTC (rev 5700)
@@ -52,7 +52,7 @@
 NODE *
 make_footnotes_node (NODE *node)
 {
-  NODE *fn_node, *result = NULL;
+  NODE *fn_node, *footnotes_node = NULL, *result = NULL;
   long fn_start;
 
   /* Make the initial assumption that the footnotes appear as simple
@@ -90,10 +90,12 @@
                   refs[i]->nodename[reflen - 1] == '-' &&
                   isdigit (refs[i]->nodename[reflen]))))
               {
-                fn_node = info_get_node (node->fullpath, refname);
-                if (fn_node)
-                  fn_start = 0;
-
+                footnotes_node = info_get_node (node->fullpath, refname);
+                if (footnotes_node)
+                  {
+                    fn_node = footnotes_node;
+                    fn_start = 0;
+                  }
                 break;
               }
 
@@ -161,6 +163,7 @@
     free (header);
   }
 
+  free (footnotes_node);
   return result;
 }
 

Modified: trunk/info/info.c
===================================================================
--- trunk/info/info.c   2014-07-05 16:26:11 UTC (rev 5699)
+++ trunk/info/info.c   2014-07-05 18:49:01 UTC (rev 5700)
@@ -355,6 +355,7 @@
           add_pointer_to_array (info_copy_reference (invoc_ref),
             ref_index, ref_list, ref_slots, 2);
         }
+      free (program);
     }
 
   /* If there are arguments remaining, they are the names of menu items

Modified: trunk/info/nodes.c
===================================================================
--- trunk/info/nodes.c  2014-07-05 16:26:11 UTC (rev 5699)
+++ trunk/info/nodes.c  2014-07-05 18:49:01 UTC (rev 5700)
@@ -993,6 +993,8 @@
   return node;
 }
 
+/* Return NODE specified with FILENAME_IN and NODENAME_IN.  Return value
+   should be freed by caller, but none of its fields should be. */
 NODE *
 info_get_node (char *filename_in, char *nodename_in)
 {
@@ -1044,7 +1046,8 @@
 /* Return a pointer to a NODE structure for the Info node NODENAME in
    FILE_BUFFER.  NODENAME can be passed as NULL, in which case the
    nodename of "Top" is used.  If the node cannot be found, return a
-   NULL pointer. */
+   NULL pointer.  Return value should be freed by caller, but none of its
+   fields should be. */
 NODE *
 info_get_node_of_file_buffer (FILE_BUFFER *file_buffer, char *nodename)
 {

Modified: trunk/info/session.c
===================================================================
--- trunk/info/session.c        2014-07-05 16:26:11 UTC (rev 5699)
+++ trunk/info/session.c        2014-07-05 18:49:01 UTC (rev 5700)
@@ -2877,12 +2877,12 @@
     window_clear_echo_area ();
 }
 
-/* Find the node that is the best candidate to list the PROGRAM's
-   invocation info and its command-line options, by looking for menu
-   items and chains of menu items with characteristic names.  Return
-   value should not be freed by caller. */
+/* Find the node in the file with Top node NODE that is the best candidate to
+   list the PROGRAM's invocation info and its command-line options, by looking
+   for menu items and chains of menu items with characteristic names.  This
+   function frees NODE.  Return value should not be freed by caller. */
 REFERENCE *
-info_intuit_options_node (NODE *initial_node, char *program)
+info_intuit_options_node (NODE *node, char *program)
 {
   /* The list of node names typical for GNU manuals where the program
      usage and specifically the command-line arguments are described.
@@ -2907,7 +2907,6 @@
     "%s",               /* last resort */
     (const char *)0
   };
-  NODE *node = NULL;
   REFERENCE *entry = NULL;
 
   const char **try_node;
@@ -2916,14 +2915,14 @@
      there are no more menus or no menu items from the above list.
      Some manuals have the invocation node sitting 3 or 4 levels deep
      in the menu hierarchy...  */
-  for (node = initial_node; node; initial_node = node)
+  while (1)
     {
       REFERENCE *new_entry = NULL;
 
       /* If no menu in this node, stop here.  Perhaps this node
          is the one they need.  */
-      if (!initial_node->references)
-        return entry;
+      if (!node->references)
+        break;
 
       /* Look for node names typical for usage nodes in this menu.  */
       for (try_node = invocation_nodes; *try_node; try_node++)
@@ -2935,7 +2934,7 @@
           /* The last resort "%s" is dangerous, so we restrict it
              to exact matches here.  */
           new_entry = info_get_menu_entry_by_label
-            (initial_node, nodename, strcmp (*try_node, "%s"));
+            (node, nodename, strcmp (*try_node, "%s"));
           free (nodename);
           if (new_entry)
             break;
@@ -2949,14 +2948,17 @@
       /* Go down into menu, and repeat. */ 
 
       if (!entry->filename)
-        entry->filename = xstrdup (initial_node->fullpath);
+        entry->filename = xstrdup (node->fullpath);
 
+      free (node);
+
       /* Try to find this node.  */
       node = info_get_node (entry->filename, entry->nodename);
       if (!node)
         break;
     }
 
+  free (node);
   return entry;  
 }
 
@@ -3017,6 +3019,8 @@
   top_node = info_get_node (file_name, 0);
   if (!top_node)
     info_error (msg_cant_find_node, "Top");
+  else
+    window_clear_echo_area ();
 
   invocation_ref = info_intuit_options_node (top_node, program_name);
 
@@ -3024,8 +3028,6 @@
   if (invocation_ref)
     info_select_reference (window, invocation_ref);
 
-  if (!info_error_was_printed)
-    window_clear_echo_area ();
   free (line);
   free (default_program_name);
 }
@@ -3238,7 +3240,10 @@
   debug (1, (_("writing node %s..."), node_printed_rep (node)));
 
   if (write_node_to_stream (node, stream))
-    return DUMP_SYS_ERROR;
+    {
+      free (node);
+      return DUMP_SYS_ERROR;
+    }
 
   /* If we are dumping subnodes, get the list of menu items in this node,
      and dump each one recursively. */
@@ -3260,14 +3265,16 @@
                  current one. */
               if (!menu[i]->filename)
                 if (dump_node_to_stream (filename, menu[i]->nodename,
-                                        stream, dump_subnodes) == 
DUMP_SYS_ERROR)
-                 return DUMP_SYS_ERROR;
+                      stream, dump_subnodes) == DUMP_SYS_ERROR)
+                  {
+                    free (node);
+                    return DUMP_SYS_ERROR;
+                  }
             }
         }
     }
 
   free (node);
-
   return DUMP_SUCCESS;
 }
 
@@ -3658,10 +3665,9 @@
           if (dir < 0)
             start = tag->nodelen;
 
-          result =
-            info_search_in_node_internal (string, node, start, window, dir,
-                                         case_sensitive, 1, use_regex,
-                                         &ret, resbnd);
+          result = info_search_in_node_internal (string, node, start, window,
+                      dir, case_sensitive, 1, use_regex, &ret, resbnd);
+          free (node);
 
           /* Did we find the string in this node? */
           if (result == search_success)
@@ -3677,10 +3683,7 @@
               return 0;
             }
 
-          /* No.  Free this node, and make sure that we haven't passed
-             our starting point. */
-          free (node);
-
+          /* No.  Make sure that we haven't passed our starting point. */
           if (result == search_failure
              || strcmp (initial_nodename, tag->nodename) == 0)
             return -1;




reply via email to

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