texinfo-commits
[Top][All Lists]
Advanced

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

[8096] XS avoid memory leak


From: gavinsmith0123
Subject: [8096] XS avoid memory leak
Date: Thu, 16 Aug 2018 12:11:54 -0400 (EDT)

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

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/tp/Texinfo/XS/text.c
    trunk/tp/Texinfo/XS/text.h
    trunk/tp/Texinfo/XS/xspara.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2018-08-16 15:56:11 UTC (rev 8095)
+++ trunk/ChangeLog     2018-08-16 16:11:53 UTC (rev 8096)
@@ -1,5 +1,12 @@
 2018-08-16  Gavin Smith  <address@hidden>
 
+       * tp/Texinfo/XS/xspara.c (xspara_get_pending, xspara_add_pending_word)
+       xspara_end, xspara_add_next, xspara_add_text): Save storage for 
+       text buffers in static variables to avoid memory leak.
+       * tp/Texinfo/XS/text.c (text_reset): New function.
+
+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 

Modified: trunk/tp/Texinfo/XS/text.c
===================================================================
--- trunk/tp/Texinfo/XS/text.c  2018-08-16 15:56:11 UTC (rev 8095)
+++ trunk/tp/Texinfo/XS/text.c  2018-08-16 16:11:53 UTC (rev 8096)
@@ -1,4 +1,4 @@
-/* Copyright 2014, 2015, 2016 Free Software Foundation, Inc.
+/* Copyright 2014, 2015, 2016, 2018 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -68,7 +68,18 @@
   text_append_n (t, s, len);
 }
 
+/* Set text to an empty string without clearing any storage */
 void
+text_reset (TEXT *t)
+{
+  if (t->end > 0)
+    {
+      t->end = 0;
+      t->text[0] = 0;
+    }
+}
+
+void
 text_init (TEXT *t)
 {
   t->end = t->space = 0;

Modified: trunk/tp/Texinfo/XS/text.h
===================================================================
--- trunk/tp/Texinfo/XS/text.h  2018-08-16 15:56:11 UTC (rev 8095)
+++ trunk/tp/Texinfo/XS/text.h  2018-08-16 16:11:53 UTC (rev 8096)
@@ -1,4 +1,4 @@
-/* Copyright 2014, 2015, 2016 Free Software Foundation, Inc.
+/* Copyright 2014, 2015, 2016, 2018 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -20,6 +20,7 @@
 } TEXT;
 
 void text_init (TEXT *t);
+void text_reset (TEXT *t);
 void text_append (TEXT *t, char *s);
 void text_append_n (TEXT *t, char *s, size_t len);
 void text_printf (TEXT *t, char *format, ...);

Modified: trunk/tp/Texinfo/XS/xspara.c
===================================================================
--- trunk/tp/Texinfo/XS/xspara.c        2018-08-16 15:56:11 UTC (rev 8095)
+++ trunk/tp/Texinfo/XS/xspara.c        2018-08-16 16:11:53 UTC (rev 8096)
@@ -1,4 +1,4 @@
-/* Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free Software
+/* Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2018 Free Software
    Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
@@ -553,8 +553,8 @@
 char *
 xspara_get_pending (void)
 {
-  TEXT t;
-  text_init (&t);
+  static TEXT t;
+  text_reset (&t);
   text_append_n (&t, state.space.text, state.space.end);
   text_append_n (&t, state.word.text, state.word.end);
   return t.text;
@@ -610,9 +610,9 @@
 char *
 xspara_add_pending_word (int add_spaces)
 {
-  TEXT ret;
+  static TEXT ret;
 
-  text_init (&ret);
+  text_reset (&ret);
   state.end_line_count = 0;
   xspara__add_pending_word (&ret, add_spaces);
   if (ret.text)
@@ -625,8 +625,8 @@
 char *
 xspara_end (void)
 {
-  TEXT ret;
-  text_init (&ret);
+  static TEXT ret;
+  text_reset (&ret);
   state.end_line_count = 0;
   xspara__add_pending_word (&ret, state.add_final_space);
   if (!state.no_final_newline && state.counter != 0)
@@ -773,9 +773,9 @@
 char *
 xspara_add_next (char *text, int text_len, int transparent)
 {
-  TEXT t;
+  static TEXT t;
 
-  text_init (&t);
+  text_reset (&t);
   state.end_line_count = 0;
   xspara__add_next (&t, text, text_len, transparent);
 
@@ -883,10 +883,10 @@
   int len;
   wchar_t wc;
   size_t char_len;
-  TEXT result;
+  static TEXT result;
   dTHX;
 
-  text_init (&result);
+  text_reset (&result);
 
   len = strlen (text); /* FIXME: Get this as an argument */
   state.end_line_count = 0;
@@ -973,13 +973,13 @@
                               /* Truncate to at most 2 spaces, and replace any 
                                  '\n' or '\r' characters with ' '. */
 
-                              TEXT new_space;
+                              static TEXT new_space;
                               char *pspace;
                               int pspace_left;
                               int len;
                               int i;
 
-                              text_init (&new_space);
+                              text_reset (&new_space);
                               pspace = state.space.text;
                               pspace_left = state.space.end;
                               state.space_counter = 0;




reply via email to

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