texinfo-commits
[Top][All Lists]
Advanced

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

[5785] fix info memory leaks


From: Gavin D. Smith
Subject: [5785] fix info memory leaks
Date: Tue, 26 Aug 2014 14:17:35 +0000

Revision: 5785
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5785
Author:   gavin
Date:     2014-08-26 14:17:33 +0000 (Tue, 26 Aug 2014)
Log Message:
-----------
fix info memory leaks

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/dir.c
    trunk/info/info-utils.c
    trunk/info/info.c
    trunk/info/m-x.c
    trunk/info/search.c
    trunk/info/session.c
    trunk/info/t/Init-inter.inc
    trunk/info/t/Init-test.inc

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-08-25 19:52:58 UTC (rev 5784)
+++ trunk/ChangeLog     2014-08-26 14:17:33 UTC (rev 5785)
@@ -1,3 +1,24 @@
+2014-08-26  Gavin Smith  <address@hidden>
+
+       * info/m-x.c (info_execute_command): Free a string.  Allow arbitarily
+       long prompts.
+       * info/info.c (main): Exit with exit() instead of 'return' to avoid
+       memory leak report from valgrind for main's local variables.
+       (initial_fb): New static variable, taken out of 'main' function.
+       (get_initial_file): Don't clobber 'filename' field of dir entry.
+       * info/search.c (find_node_in_binding): Free last string allocated in
+       a loop.
+       * info/session.c (info_search_in_node_internal): Free 'search_string'
+       field of WINDOW before overwriting it.
+       * info/dir.c (lookup_dir_entry),
+       * info/info-utils.c (info_copy_reference, info_copy_references):
+       Comments changed.
+
+       * info/t/Init-test.inc: Commented-out line added showing how to run
+       tests under valgrind.
+       * info/t/Init-inter.inc: Get name of running "ginfo" process from a
+       variable.
+
 2014-08-25  Gavin Smith  <address@hidden>
 
        * info/dir.c (insert_text_into_node): Include terminating null byte

Modified: trunk/info/dir.c
===================================================================
--- trunk/info/dir.c    2014-08-25 19:52:58 UTC (rev 5784)
+++ trunk/info/dir.c    2014-08-26 14:17:33 UTC (rev 5785)
@@ -250,6 +250,7 @@
   node->nodelen += textlen;
 }
 
+/* Return directory entry.  Return value should not be freed or modified. */
 REFERENCE *
 lookup_dir_entry (char *label, int sloppy)
 {

Modified: trunk/info/info-utils.c
===================================================================
--- trunk/info/info-utils.c     2014-08-25 19:52:58 UTC (rev 5784)
+++ trunk/info/info-utils.c     2014-08-26 14:17:33 UTC (rev 5785)
@@ -302,9 +302,7 @@
   return result;
 }
 
-/* Copy a reference structure.  Since we tend to free everything at
-   every opportunity, we don't share any points, but copy everything into
-   new memory.  */
+/* Copy a reference structure.  Copy each field into new memory.  */
 REFERENCE *
 info_copy_reference (REFERENCE *src)
 {
@@ -320,8 +318,8 @@
   return dest;
 }
 
-/* Copy a list of references. */
-/* FIXME: Use info_concatenate_references with one null argument instead. */
+/* Copy a list of references, copying in reference in turn with
+   info_copy_reference. */
 REFERENCE **
 info_copy_references (REFERENCE **ref1)
 {

Modified: trunk/info/info.c
===================================================================
--- trunk/info/info.c   2014-08-25 19:52:58 UTC (rev 5784)
+++ trunk/info/info.c   2014-08-26 14:17:33 UTC (rev 5785)
@@ -57,6 +57,9 @@
 /* Name of file to start session with. */
 static char *initial_file = 0;
 
+/* File to start session with. */
+static FILE_BUFFER *initial_fb = 0;
+
 /* Array of the names of nodes that the user specified with "--node" on the
    command line. */
 static char **user_nodenames = NULL;
@@ -187,14 +190,16 @@
           initial_file = info_find_fullpath (entry->filename, 0);
           if (initial_file)
             {
+              REFERENCE *copy;
               (*argv)++; /* Advance past first remaining argument. */
               (*argc)--;
 
+              copy = info_copy_reference (entry);
               /* Store full path, so that we find the already loaded file in
                  info_find_file, and show the full path if --where is used. */
-              entry->filename = initial_file;
-              add_pointer_to_array (info_copy_reference (entry),
-                  ref_index, ref_list, ref_slots, 2);
+              free (copy->filename);
+              copy->filename = xstrdup (initial_file);
+              add_pointer_to_array (copy, ref_index, ref_list, ref_slots, 2);
               return;
             }
         }
@@ -257,18 +262,20 @@
       entry = lookup_dir_entry ((*argv)[0], 1);
       if (entry)
         {
+          REFERENCE *copy;
           (*argv)++; /* Advance past first remaining argument. */
           (*argc)--;
           /* Clear error message. */
           free (*error);
           *error = 0;
 
+          copy = info_copy_reference (entry);
           initial_file = info_find_fullpath (entry->filename, 0);
           /* Store full path, so that we find the already loaded file in
              info_find_file, and show the full path if --where is used. */
-          entry->filename = initial_file;
-          add_pointer_to_array (info_copy_reference (entry),
-              ref_index, ref_list, ref_slots, 2);
+          free (copy->filename);
+          copy->filename = initial_file;
+          add_pointer_to_array (copy, ref_index, ref_list, ref_slots, 2);
           return;
         }
     }
@@ -549,7 +556,6 @@
 {
   int getopt_long_index;       /* Index returned by getopt_long (). */
   char *init_file = 0;         /* Name of init file specified. */
-  FILE_BUFFER *initial_fb = 0; /* File to start session with. */
   char *error = 0;             /* Error message to display in mini-buffer. */
 
 #ifdef HAVE_SETLOCALE
@@ -785,15 +791,15 @@
       if (!apropos_list)
         info_error (_(APROPOS_NONE), apropos_search_string);
       else
-      {
-        register int i;
-        REFERENCE *entry;
+        {
+          register int i;
+          REFERENCE *entry;
 
-        for (i = 0; (entry = apropos_list[i]); i++)
-          fprintf (stdout, "\"(%s)%s\" -- %s\n",
-              entry->filename, entry->nodename, entry->label);
-      }
-      exit (EXIT_SUCCESS);
+          for (i = 0; (entry = apropos_list[i]); i++)
+            fprintf (stdout, "\"(%s)%s\" -- %s\n",
+                entry->filename, entry->nodename, entry->label);
+        }
+      exit (0);
     }
 
   /* Initialize empty list of nodes to load. */
@@ -809,7 +815,9 @@
           argv++; argc--;
         }
       else if (!user_filename)
-        return 1;
+        {
+          exit (1);
+        }
       info_find_matching_files (user_filename);
     }
   else
@@ -830,14 +838,14 @@
                                     index_search_string);
               info_read_and_dispatch ();
               close_info_session ();
-              return 0;
+              exit (0);
             }
           else
             {
               fprintf (stderr, _("no index entries found for `%s'\n"),
                        index_search_string);
               close_dribble_file ();
-              return 1;
+              exit (1);
             }
         }
 
@@ -858,11 +866,11 @@
     {
       int i;
       if (!ref_list)
-        return 1;
+        exit (1);
 
       for (i = 0; ref_list[i]; i++)
         printf ("%s\n", ref_list[i]->filename);
-      return 0;
+      exit (0);
     }
 
   /* --output */
@@ -873,18 +881,18 @@
 
       preprocess_nodes_p = 0;
       dump_nodes_to_file (ref_list, user_output_filename, dump_subnodes);
-      return 0;
+      exit (0);
     }
 
   if (user_filename && error)
     {
       info_error (error);
-      return 1;
+      exit (0);
     }
     
   info_session (ref_list, all_matches_p ? user_filename : 0, error);
   close_info_session ();
-  return 0;
+  exit (0);
 }
 
 void

Modified: trunk/info/m-x.c
===================================================================
--- trunk/info/m-x.c    2014-08-25 19:52:58 UTC (rev 5784)
+++ trunk/info/m-x.c    2014-08-26 14:17:33 UTC (rev 5785)
@@ -93,8 +93,6 @@
   char *keys;
   char *prompt;
 
-  prompt = xmalloc (20);
-
   keys = where_is (info_keymap, InfoCmd(info_execute_command));
   /* If the where_is () function thinks that this command doesn't exist,
      there's something very wrong!  */
@@ -102,12 +100,13 @@
     abort();
 
   if (info_explicit_arg || count != 1)
-    sprintf (prompt, "%d %s ", count, keys);
+    asprintf (&prompt, "%d %s ", count, keys);
   else
-    sprintf (prompt, "%s ", keys);
+    asprintf (&prompt, "%s ", keys);
 
   /* Ask the completer to read a reference for us. */
   line = read_function_name (prompt, window);
+  free (prompt);
 
   /* User aborted? */
   if (!line)

Modified: trunk/info/search.c
===================================================================
--- trunk/info/search.c 2014-08-25 19:52:58 UTC (rev 5784)
+++ trunk/info/search.c 2014-08-26 14:17:33 UTC (rev 5785)
@@ -538,6 +538,7 @@
     {
       char *nodename_start;
       char *read_nodename;
+      int found;
 
       s.start = position;
       s.start += skip_node_separator (s.buffer + s.start);
@@ -554,11 +555,11 @@
       if (!read_nodename)
         return -1;
 
-      if (!strcmp (read_nodename, nodename))
-        {
-          free (read_nodename);
-          return position;
-        }
+      found = !strcmp (read_nodename, nodename);
+      free (read_nodename);
+
+      if (found)
+        return position;
     }
   return -1;
 }

Modified: trunk/info/session.c
===================================================================
--- trunk/info/session.c        2014-08-25 19:52:58 UTC (rev 5784)
+++ trunk/info/session.c        2014-08-26 14:17:33 UTC (rev 5785)
@@ -3559,6 +3559,7 @@
       free (window->matches);
       window->matches = 0;
 
+      free (window->search_string);
       window->search_string = xstrdup (string);
       window->search_is_case_sensitive = case_sensitive;
       result = regexp_search (string, !match_regexp, !case_sensitive,

Modified: trunk/info/t/Init-inter.inc
===================================================================
--- trunk/info/t/Init-inter.inc 2014-08-25 19:52:58 UTC (rev 5784)
+++ trunk/info/t/Init-inter.inc 2014-08-26 14:17:33 UTC (rev 5785)
@@ -56,7 +56,7 @@
   GINFO_PID=
   while :
   do
-    GINFO_PID=$( pgrep -P $SUBSHELL ginfo ; \
+    GINFO_PID=$( pgrep -P $SUBSHELL $GINFO_NAME ; \
        test $? -eq 0 -o $? -eq 1 || exit 99 )
 
     # This use of pgrep is likely not portable (works on procps).  Check if it

Modified: trunk/info/t/Init-test.inc
===================================================================
--- trunk/info/t/Init-test.inc  2014-08-25 19:52:58 UTC (rev 5784)
+++ trunk/info/t/Init-test.inc  2014-08-26 14:17:33 UTC (rev 5785)
@@ -4,8 +4,14 @@
 # Allow running with "make check" and individual tests at the command-line
 srcdir=${srcdir:-.}
 
+# Use the second line to run the program under valgrind.
 GINFO="./ginfo --init-file $srcdir/t/Infokey-config"
+#GINFO="valgrind --log-file=$0.val.log --leak-check=full ./ginfo --init-file 
$srcdir/t/Infokey-config"
 
+# Set this to the name of the process
+GINFO_NAME=ginfo
+#GINFO_NAME=memcheck-x86-li
+
 # Only look for Info files in our test directory
 export infodir=$srcdir/t/infodir
 export INFOPATH=$infodir




reply via email to

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