texinfo-commits
[Top][All Lists]
Advanced

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

[8095] MiscXS avoid memory leak


From: gavinsmith0123
Subject: [8095] MiscXS avoid memory leak
Date: Thu, 16 Aug 2018 11:56:12 -0400 (EDT)

Revision: 8095
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=8095
Author:   gavin
Date:     2018-08-16 11:56:11 -0400 (Thu, 16 Aug 2018)
Log Message:
-----------
MiscXS avoid memory leak

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/tp/Texinfo/XS/misc.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2018-08-16 13:20:45 UTC (rev 8094)
+++ trunk/ChangeLog     2018-08-16 15:56:11 UTC (rev 8095)
@@ -1,5 +1,13 @@
 2018-08-16  Gavin Smith  <address@hidden>
 
+       * tp/Texinfo/XS/misc.c (xs_parse_texi_regex): Retain all memory
+       allocated on the heap in static pointers.  Perl does not free 
+       them, as when SV's are initialized with sv_setpv, the data 
+       pointed to is copied, not the pointer itself.  This memory leak 
+       is visible with valgrind, e.g. run TEXINFO_XS=debug 
PERL_DESTRUCT_LEVEL=2 valgrind --log-file=val.log --leak-check=full perl -w 
t/02coverage.t commands
+
+2018-08-16  Gavin Smith  <address@hidden>
+
        * tp/Makefile.am (EXTRA_DIST) Do not distribute tp/Makefile.PL 
        or tp/MANIFEST.
        * tp/Texinfo/XS/Makefile.am: Do not distribute Makefile.PL,

Modified: trunk/tp/Texinfo/XS/misc.c
===================================================================
--- trunk/tp/Texinfo/XS/misc.c  2018-08-16 13:20:45 UTC (rev 8094)
+++ trunk/tp/Texinfo/XS/misc.c  2018-08-16 15:56:11 UTC (rev 8095)
@@ -612,21 +612,24 @@
   if (*text == '@' && isalnum(text[1]))
     {
       char *p, *q;
+      static char *s;
 
       p = text + 1;
       q = text + 2;
       while (isalnum (*q) || *q == '-' || *q == '_')
         q++;
-      *at_command = malloc (q - p + 1);
-      memcpy (*at_command, p, q - p);
-      (*at_command)[q - p] = '\0';
+      
+      s = realloc (s, q - p + 1);
+      memcpy (s, p, q - p);
+      s[q - p] = '\0';
+      *at_command = s;
     }
   else
     {
       if (*text == '{')
         {
-          *open_brace = strdup ("{");
-          *separator_match = strdup ("{");
+          *open_brace = "{";
+          *separator_match = "{";
         }
 
       else if (*text == '@'
@@ -635,16 +638,18 @@
                                        "*-^`=:|/\\",
                                        text[1]))
         {
-          *single_letter_command = malloc (2);
-          (*single_letter_command)[0] = text[1];
-          (*single_letter_command)[1] = '\0';
+          static char a[2];
+          *single_letter_command = a;
+          a[0] = text[1];
+          a[1] = '\0';
         }
 
       else if (strchr ("{}@,:\t.\f", *text))
         {
-          *separator_match = malloc (2);
-          (*separator_match)[0] = *text;
-          (*separator_match)[1] = '\0';
+          static char a[2];
+          *separator_match = a;
+          a[0] = *text;
+          a[1] = '\0';
         }
 
       else
@@ -652,17 +657,17 @@
           char *p;
 
           if (*text == '*')
-            {
-              *asterisk = strdup ("*");
-            }
+            *asterisk = "*";
 
           p = text;
           p += strcspn (p, "{}@,:\t.\n\f");
           if (p > text)
             {
-              *new_text = malloc (p - text + 1);
-              memcpy (*new_text, text, p - text);
-              (*new_text)[p - text] = '\0';
+              static char *s;
+              s = realloc (s, p - text + 1);
+              memcpy (s, text, p - text);
+              s[p - text] = '\0';
+              *new_text = s;
             }
         }
     }




reply via email to

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