Hello,

Patch fixing issues found by static analysis of the code is attached.
(mostly memory leaks).

I tried to be verbose in commit messages and usually the problem is
pretty much obvious. Please review the patch and consider to apply it.

Best regards,
Vitezslav Crhonek

-- 
Vitezslav Crhonek
Software Engineer
Red Hat
>From 696536608b273b0389820b41eccd22077ac363ae Mon Sep 17 00:00:00 2001
From: Vitezslav Crhonek <[email protected]>
Date: Wed, 17 Mar 2021 11:23:33 +0100
Subject: [PATCH 1/8] Fix ShellCheck SC1083 warning

https://github.com/koalaman/shellcheck/wiki/SC1083
This is only for suppresing the warning, both '{' and '}'
are supposed to be literals.
---
 util/texi2dvi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/texi2dvi b/util/texi2dvi
index ededbc3573..f1cbaef3c0 100755
--- a/util/texi2dvi
+++ b/util/texi2dvi
@@ -1695,7 +1695,7 @@ cleanup ()
 input_file_name_decode ()
 {
   case $command_line_filename in
-    *\\input{*}*)
+    *\\input\{*\}*)
       # Let AUC-TeX error parser deal with line numbers.
       line_error=false
       command_line_filename=`\
-- 
2.26.2


>From 9da6053e115e8abc07f8c877dde2d39af0c5101f Mon Sep 17 00:00:00 2001
From: Vitezslav Crhonek <[email protected]>
Date: Wed, 17 Mar 2021 11:30:43 +0100
Subject: [PATCH 2/8] Fix memory leak

info_add_extension() returns new string based on 'dirname'. But that
is the last usage of 'dirname' in the function.
Free it to aviod memory leak at the end of the function (no matter
which end it would be).
---
 info/filesys.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/info/filesys.c b/info/filesys.c
index c49088d66a..cfa06c0d77 100644
--- a/info/filesys.c
+++ b/info/filesys.c
@@ -158,6 +158,7 @@ info_file_find_next_in_path (char *filename, int *path_index, struct stat *finfo
         }
 
       with_extension = info_add_extension (dirname, filename, finfo);
+      free (dirname);
 
       if (with_extension)
         {
-- 
2.26.2


>From 18b373be8b6ae2e14a3929d421477465faa30b0c Mon Sep 17 00:00:00 2001
From: Vitezslav Crhonek <[email protected]>
Date: Wed, 17 Mar 2021 11:36:48 +0100
Subject: [PATCH 3/8] Remove unused variable

---
 contrib/fix-info-dir | 1 -
 1 file changed, 1 deletion(-)

diff --git a/contrib/fix-info-dir b/contrib/fix-info-dir
index b1144ed6a4..0659552146 100755
--- a/contrib/fix-info-dir
+++ b/contrib/fix-info-dir
@@ -28,7 +28,6 @@ if test -z "$LINENO"; then
 fi
 
 MENU_BEGIN='^\*\([ 	]\)\{1,\}Menu:'
-MENU_ITEM='^\* ([^ 	]).*:([ 	])+\('
 MENU_FILTER1='s/^\*\([ 	]\)\{1,\}/* /'
 MENU_FILTER2='s/\([ 	]\)\{1,\}$//g'
 
-- 
2.26.2


>From 458688d5449d38c389f7e81286957c18287dfb7b Mon Sep 17 00:00:00 2001
From: Vitezslav Crhonek <[email protected]>
Date: Wed, 17 Mar 2021 11:42:42 +0100
Subject: [PATCH 4/8] Fix memory leak

The memory is freed for both pointers at the end of the loop.
But there is one break that leaves the loop without freeing them.
---
 info/makedoc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/info/makedoc.c b/info/makedoc.c
index 5842cd6986..93895aa939 100644
--- a/info/makedoc.c
+++ b/info/makedoc.c
@@ -425,7 +425,11 @@ process_one_file (char *filename, FILE *doc_stream, FILE *funs_stream)
 
       offset++;
       if (offset >= file_size)
-        break;
+        {
+          free (func_name);
+          free (func);
+          break;
+        }
 
       doc = xmalloc (1 + (offset - point));
       strncpy (doc, buffer + point, offset - point);
-- 
2.26.2


>From 1b87c4cda80cc776a7fc83d4ebb9a423d0a6051d Mon Sep 17 00:00:00 2001
From: Vitezslav Crhonek <[email protected]>
Date: Wed, 17 Mar 2021 11:46:56 +0100
Subject: [PATCH 5/8] Fix memory leak

'line' is freed at the regular end of the function, but not at this
particular 'return'.
---
 info/m-x.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/info/m-x.c b/info/m-x.c
index 64984bbb34..b93f952a68 100644
--- a/info/m-x.c
+++ b/info/m-x.c
@@ -79,7 +79,10 @@ DECLARE_INFO_COMMAND (describe_command,
       InfoCommand *cmd = named_function (line);
 
       if (!cmd)
-        return;
+        {
+          free (line);
+          return;
+        }
 
       window_message_in_echo_area ("%s: %s.",
                                    line, function_documentation (cmd));
-- 
2.26.2


>From b52d3e8f0cb45ae980c15631f0079db958a84d8a Mon Sep 17 00:00:00 2001
From: Vitezslav Crhonek <[email protected]>
Date: Wed, 17 Mar 2021 11:53:26 +0100
Subject: [PATCH 6/8] Fix memory leak

info_create_tag() returns a pointer to a newly allocated TAG structure.
Before continuing to the start of the loop it is necessary to free the
current TAG structure, because the pointer will be overwritten by
new value in the next iteration of the loop.
---
 info/nodes.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/info/nodes.c b/info/nodes.c
index 47228258f2..631e7af31c 100644
--- a/info/nodes.c
+++ b/info/nodes.c
@@ -303,7 +303,10 @@ get_nodes_of_tags_table (FILE_BUFFER *file_buffer,
       for (p = 0; nodedef[p] && nodedef[p] != INFO_TAGSEP; p++)
         ;
       if (nodedef[p] != INFO_TAGSEP)
-        continue;
+        {
+          free (entry);
+          continue;
+        }
 
       entry->nodename = xmalloc (p + 1);
       strncpy (entry->nodename, nodedef, p);
-- 
2.26.2


>From 3d9e36af398e05f50fdd6ca72f2371f493fe6b45 Mon Sep 17 00:00:00 2001
From: Vitezslav Crhonek <[email protected]>
Date: Wed, 17 Mar 2021 11:58:34 +0100
Subject: [PATCH 7/8] Fix memory leak

This is done at the end of the function, probably forgetfully omitted
here.
---
 info/nodes.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/info/nodes.c b/info/nodes.c
index 631e7af31c..3c941408e2 100644
--- a/info/nodes.c
+++ b/info/nodes.c
@@ -480,6 +480,7 @@ get_tags_of_indirect_tags_table (FILE_BUFFER *file_buffer,
                 }
               file_buffer->subfiles = NULL;
               free_file_buffer_tags (file_buffer);
+              free (subfiles);
               return;
             }
 
-- 
2.26.2


>From f5d6954e52476325f6e6eb444436c156ba589185 Mon Sep 17 00:00:00 2001
From: Vitezslav Crhonek <[email protected]>
Date: Wed, 17 Mar 2021 12:02:16 +0100
Subject: [PATCH 8/8] Fix memory leak

The value of 'default_program_name' is assigned by
program_name_from_file_name() function.
Its description says 'Return value should be freed by caller.'
That was not done in this case.
---
 info/session.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/info/session.c b/info/session.c
index 3ca16349c9..d67641b702 100644
--- a/info/session.c
+++ b/info/session.c
@@ -3563,6 +3563,7 @@ DECLARE_INFO_COMMAND (info_goto_invocation_node,
   if (!line)
     {
       info_abort_key (window, 0);
+      free (default_program_name);
       return;
     }
   if (*line)
-- 
2.26.2

Reply via email to