texinfo-commits
[Top][All Lists]
Advanced

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

[5902] memory leaks for failing searches


From: Gavin D. Smith
Subject: [5902] memory leaks for failing searches
Date: Wed, 29 Oct 2014 20:48:02 +0000

Revision: 5902
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5902
Author:   gavin
Date:     2014-10-29 20:48:02 +0000 (Wed, 29 Oct 2014)
Log Message:
-----------
memory leaks for failing searches

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/search.c
    trunk/info/session.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-10-29 20:18:06 UTC (rev 5901)
+++ trunk/ChangeLog     2014-10-29 20:48:02 UTC (rev 5902)
@@ -6,6 +6,11 @@
        (incremental_search): Don't say an empty search string is 
        failing.
 
+       * info/search.c (regexp_search): Don't allocate a match list if 
+       there aren't any matches.
+       * info/session.c (info_search_internal): Always free return 
+       value of info_get_node if it is not saved in the window.
+
 2014-10-29  Karl Berry  <address@hidden>
 
        * doc/texinfo.tex (\chapmacro): \checkenv, since chapters

Modified: trunk/info/search.c
===================================================================
--- trunk/info/search.c 2014-10-29 20:18:06 UTC (rev 5901)
+++ trunk/info/search.c 2014-10-29 20:48:02 UTC (rev 5902)
@@ -173,22 +173,25 @@
   for (match_count = 0; offset < buflen; )
     {
       int result = 0;
-      if (match_count == match_alloc)
-        {
-          /* The match list is full.  Initially allocate 256 entries,
-             then double every time we fill it. */
-          if (match_alloc == 0)
-            match_alloc = 256;
-          matches = x2nrealloc (matches, &match_alloc, sizeof matches[0]);
-        }
+      regmatch_t m;
 
-      result = regexec (&preg, &buffer[offset], 1, &matches[match_count], 0);
+      result = regexec (&preg, &buffer[offset], 1, &m, 0);
       if (result == 0)
         {
-          if (matches[match_count].rm_eo == 0)
+          if (m.rm_eo == 0)
             offset++; /* Ignore empty matches. */
           else
             {
+              if (match_count == match_alloc)
+                {
+                  /* The match list is full. */
+                  if (match_alloc == 0)
+                    match_alloc = 50;
+                  matches = x2nrealloc
+                    (matches, &match_alloc, sizeof matches[0]);
+                }
+
+              matches[match_count] = m;
               matches[match_count].rm_so += offset;
               matches[match_count].rm_eo += offset;
               offset = matches[match_count++].rm_eo;

Modified: trunk/info/session.c
===================================================================
--- trunk/info/session.c        2014-10-29 20:18:06 UTC (rev 5901)
+++ trunk/info/session.c        2014-10-29 20:48:02 UTC (rev 5902)
@@ -4070,6 +4070,7 @@
           subfile_name = tag->subfile;
         }
 
+      /* Get a new node to search in. */
       if (node != window->node)
         free (node);
       free (window->matches);
@@ -4099,13 +4100,16 @@
       /* Allow C-g to quit the search, failing it if pressed. */
       fill_input_buffer (0); \
       if (info_input_buffer[pop_index] == Control ('g'))
-        return -1;
+        goto funexit;
     }
 
   /* Not in interactive search. */
   if (!echo_area_is_active)
     info_error ("%s", _("Search failed."));
 
+funexit:
+  if (node != window->node)
+    free (node);
   return -1;
 }
 




reply via email to

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