texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: Remove memory leaks (valgrind)


From: Patrice Dumas
Subject: branch master updated: Remove memory leaks (valgrind)
Date: Sun, 19 May 2024 08:20:51 -0400

This is an automated email from the git hooks/post-receive script.

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new b0b386a5bb Remove memory leaks (valgrind)
b0b386a5bb is described below

commit b0b386a5bb4e1d358580204262ac0cf7563c62c8
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun May 19 14:20:45 2024 +0200

    Remove memory leaks (valgrind)
    
    * tp/Texinfo/XS/parsetexi/api.c (parser_reset_values_conf): wipe
    conf values.
    
    * tp/Texinfo/XS/parsetexi/conf.c (reset_conf): do not call memset, in
    order to keep and reuse the conf.values list.  Wipe conf values.
    
    * tp/Texinfo/XS/parsetexi/macro.c (init_values): wipe parser values.
    
    * tp/Texinfo/XS/convert/convert_html.c,
    tp/Texinfo/XS/main/output_unit.c: remove memory leaks in debug
    messages.
---
 ChangeLog                            | 16 ++++++++++++++++
 tp/TODO                              |  7 +++++++
 tp/Texinfo/XS/convert/convert_html.c | 28 ++++++++++++++++++++--------
 tp/Texinfo/XS/main/output_unit.c     | 10 +++++++---
 tp/Texinfo/XS/parsetexi/api.c        |  4 ++--
 tp/Texinfo/XS/parsetexi/conf.c       | 10 ++++++++--
 tp/Texinfo/XS/parsetexi/macro.c      |  4 +++-
 7 files changed, 63 insertions(+), 16 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2bcc1edaf5..e49e7e4839 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2024-05-19  Patrice Dumas  <pertusus@free.fr>
+
+       Remove memory leaks (valgrind)
+
+       * tp/Texinfo/XS/parsetexi/api.c (parser_reset_values_conf): wipe
+       conf values.
+
+       * tp/Texinfo/XS/parsetexi/conf.c (reset_conf): do not call memset, in
+       order to keep and reuse the conf.values list.  Wipe conf values.
+
+       * tp/Texinfo/XS/parsetexi/macro.c (init_values): wipe parser values.
+
+       * tp/Texinfo/XS/convert/convert_html.c,
+       tp/Texinfo/XS/main/output_unit.c: remove memory leaks in debug
+       messages.
+
 2024-05-18  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/main/document_types.h (VALUE, VALUE_LIST): move VALUE
diff --git a/tp/TODO b/tp/TODO
index 1e9e830e70..3ff484fe55 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -791,6 +791,13 @@ export TEXINFO_XS_PARSER=0
 for file in t/*.t ; do bfile=`basename $file .t`; perl -w $file -d 1 
2>t/check_debug_differences/PL_$bfile.err ; done
 for file in t/*.t ; do bfile=`basename $file .t`; sed 's/^XS|//' 
t/check_debug_differences/XS_$bfile.err | diff -u 
t/check_debug_differences/PL_$bfile.err - > 
t/check_debug_differences/debug_$bfile.diff; done
 
+Full check, including XS conversion and memory leaks in debug:
+export TEXINFO_XS_CONVERT=1
+PERL_DESTRUCT_LEVEL=2
+export PERL_DESTRUCT_LEVEL
+for file in t/*.t ; do bfile=`basename $file .t`; valgrind -q 
--leak-check=full perl -w $file -d 1 2>t/check_debug_differences/XS_$bfile.err 
; done
+
+
 Setting flags
 our_CFLAGS='-g -Wformat-security -Wall -Wno-parentheses -Wno-missing-braces'
 ./configure "CFLAGS=$our_CFLAGS" "PERL_EXT_CFLAGS=$our_CFLAGS"
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index ea21fe33d6..7867da408f 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -5612,9 +5612,12 @@ html_set_pages_files (CONVERTER *self, const 
OUTPUT_UNIT_LIST *output_units,
       self->output_unit_file_indices[i] = output_unit_file_idx;
       output_unit_file = &self->output_unit_files.list[output_unit_file_idx];
       if (self->conf->DEBUG.integer > 0)
-        fprintf (stderr, "Page %s: %s(%d)\n",
-                 output_unit_texi (output_unit),
+        {
+          char *output_unit_text = output_unit_texi (output_unit);
+          fprintf (stderr, "Page %s: %s(%d)\n", output_unit_text,
                  output_unit->unit_filename, output_unit_file->counter);
+          free (output_unit_text);
+        }
       free (filename);
     }
 
@@ -7920,6 +7923,7 @@ html_default_format_element_header (CONVERTER *self,
     {
       int i;
       TEXT debug_txt;
+      char *output_unit_text;
       text_init (&debug_txt);
       text_append (&debug_txt, "FORMAT elt header (");
       for (i = 0; i < output_unit->unit_contents.number; i++)
@@ -7931,7 +7935,9 @@ html_default_format_element_header (CONVERTER *self,
           text_append (&debug_txt, elt_str);
           free (elt_str);
         }
-      text_printf (&debug_txt, ") %s\n", output_unit_texi (output_unit));
+      output_unit_text = output_unit_texi (output_unit);
+      text_printf (&debug_txt, ") %s\n", output_unit_text);
+      free (output_unit_text);
       fprintf (stderr, "%s", debug_txt.text);
       free (debug_txt.text);
     }
@@ -7965,9 +7971,12 @@ html_default_format_element_header (CONVERTER *self,
         previous_is_top = 1;
 
       if (self->conf->DEBUG.integer > 0)
-        fprintf (stderr, "Header (%d, %d, %d): %s\n", previous_is_top, is_top,
-                         first_in_page,
-                         root_heading_command_to_texinfo (command));
+        {
+          char *root_heading_texi = root_heading_command_to_texinfo (command);
+          fprintf (stderr, "Header (%d, %d, %d): %s\n", previous_is_top,
+                         is_top, first_in_page, root_heading_texi);
+          free (root_heading_texi);
+        }
 
       if (is_top)
        /* use TOP_BUTTONS for top. */
@@ -9985,8 +9994,11 @@ convert_heading_command (CONVERTER *self, const enum 
command_id cmd,
   element_id = html_command_id (self, element);
 
   if (self->conf->DEBUG.integer > 0)
-    fprintf (stderr, "CONVERT elt heading %s\n",
-                     root_heading_command_to_texinfo (element));
+    {
+      char *root_heading_texi = root_heading_command_to_texinfo (element);
+      fprintf (stderr, "CONVERT elt heading %s\n", root_heading_texi);
+      free (root_heading_texi);
+    }
 
   /* All the root commands are associated to an output unit, the condition
      on associated_unit is always true. */
diff --git a/tp/Texinfo/XS/main/output_unit.c b/tp/Texinfo/XS/main/output_unit.c
index 037d469db3..ff43ee2d75 100644
--- a/tp/Texinfo/XS/main/output_unit.c
+++ b/tp/Texinfo/XS/main/output_unit.c
@@ -474,17 +474,21 @@ print_output_unit_directions (OUTPUT_UNIT *output_unit)
   TEXT result;
   int i;
   int with_direction = 0;
+  char *output_unit_text = output_unit_texi (output_unit);
+
   text_init (&result);
-  text_printf (&result, "output unit: %s\n",
-               output_unit_texi (output_unit));
+  text_printf (&result, "output unit: %s\n", output_unit_text);
+  free (output_unit_text);
 
   for (i = 0; i < RUD_type_FirstInFileNodeBack+1; i++)
     {
       OUTPUT_UNIT *direction = output_unit->directions[i];
       if (direction)
         {
+          char *direction_text = output_unit_texi (direction);
           text_printf (&result, "  %s: %s\n", relative_unit_direction_name[i],
-                       output_unit_texi (direction));
+                       direction_text);
+          free (direction_text);
           with_direction++;
         }
     }
diff --git a/tp/Texinfo/XS/parsetexi/api.c b/tp/Texinfo/XS/parsetexi/api.c
index e74f284de4..5ebbdd5ea9 100644
--- a/tp/Texinfo/XS/parsetexi/api.c
+++ b/tp/Texinfo/XS/parsetexi/api.c
@@ -38,7 +38,7 @@
 #include "context_stack.h"
 /* for clear_parser_expanded_formats and add_parser_expanded_format */
 #include "handle_commands.h"
-/* for wipe_macros store_value init_values */
+/* for wipe_macros store_value init_values wipe_values */
 #include "macro.h"
 #include "document.h"
 /* for reset_conf */
@@ -245,7 +245,7 @@ parser_set_locale_encoding (const char *value)
 void
 parser_reset_values_conf (void)
 {
-  conf.values.number = 0;
+  wipe_values (&conf.values);
 }
 
 void
diff --git a/tp/Texinfo/XS/parsetexi/conf.c b/tp/Texinfo/XS/parsetexi/conf.c
index aa186cc763..00312d492d 100644
--- a/tp/Texinfo/XS/parsetexi/conf.c
+++ b/tp/Texinfo/XS/parsetexi/conf.c
@@ -66,11 +66,17 @@ conf_set_NO_USER_COMMANDS (int i)
 void
 reset_conf (void)
 {
-  memset (&conf, 0, sizeof (conf));
+  wipe_values (&conf.values);
+
   conf.show_menu = 1;
   conf.cpp_line_directives = 1;
   conf.ignore_space_after_braced_command_name = 1;
   conf.max_macro_call_nesting = 100000;
-  conf.values.number = 0;
+  conf.no_index = 0;
+  conf.no_user_commands = 0;
+
+  /* special value always returned as 1 to mark that @ifcommandnotdefined
+     is implemented.  Note that when called from the main program it is set
+     from Perl using the configuration passed to the parser */
   store_value (&conf.values, "txicommandconditionals", "1");
 }
diff --git a/tp/Texinfo/XS/parsetexi/macro.c b/tp/Texinfo/XS/parsetexi/macro.c
index 5ae27bab64..b98a0d4f31 100644
--- a/tp/Texinfo/XS/parsetexi/macro.c
+++ b/tp/Texinfo/XS/parsetexi/macro.c
@@ -1021,12 +1021,14 @@ wipe_values (VALUE_LIST *values)
   values->number = 0;
 }
 
+/* initialize parsing run values to the configuration values */
 void
 init_values (void)
 {
   size_t i;
 
-  parser_values.number = 0;
+  wipe_values (&parser_values);
+
   if (parser_values.space < conf.values.number)
     {
       parser_values.space = conf.values.number;



reply via email to

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