bug-bash
[Top][All Lists]
Advanced

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

[PATCH] read: free ifs_chars


From: Grisha Levit
Subject: [PATCH] read: free ifs_chars
Date: Wed, 29 May 2024 15:31:09 -0400

Avoid leaking ifs_chars on more return paths.
---
 builtins/read.def | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/builtins/read.def b/builtins/read.def
index 37328efc..69a1ef4c 100644
--- a/builtins/read.def
+++ b/builtins/read.def
@@ -635,6 +635,8 @@ read_builtin (WORD_LIST *list)
          if (fd2 >= 0)
            close (fd2);
          run_unwind_frame ("read_builtin");
+         if (free_ifs)
+           free (ifs_chars);
          return (EXECUTION_FAILURE);
        }
 
@@ -894,6 +896,8 @@ add_char:
       if (errno != EINTR)
        builtin_error ("%d: %s: %s", fd, _("read error"), strerror (errno));
       run_unwind_frame ("read_builtin");
+      if (free_ifs)
+       free (ifs_chars);
       return ((t_errno != EINTR) ? EXECUTION_FAILURE : 128+lastsig);
     }
 
@@ -943,6 +947,8 @@ assign_vars:
       if (var == 0)
        {
          free (input_string);
+         if (free_ifs)
+           free (ifs_chars);
          return EXECUTION_FAILURE;     /* readonly or noassign */
        }
 
@@ -957,6 +963,8 @@ assign_vars:
          dispose_words (alist);
        }
       free (input_string);
+      if (free_ifs)
+       free (ifs_chars);
       return (retval);
     }
 #endif /* ARRAY_VARS */ 
@@ -993,6 +1001,8 @@ assign_vars:
        VUNSETATTR (var, att_invisible);
 
       free (input_string);
+      if (free_ifs)
+       free (ifs_chars);
       return (retval);
     }
 
@@ -1017,6 +1027,8 @@ assign_vars:
        {
          sh_invalidid (varname);
          free (orig_input_string);
+         if (free_ifs)
+           free (ifs_chars);
          return (EXECUTION_FAILURE);
        }
 
@@ -1049,6 +1061,8 @@ assign_vars:
       if (var == 0)
        {
          free (orig_input_string);
+         if (free_ifs)
+           free (ifs_chars);
          return (EX_MISCERROR);
        }
 
@@ -1066,6 +1080,8 @@ assign_vars:
     {
       sh_invalidid (list->word->word);
       free (orig_input_string);
+      if (free_ifs)
+       free (ifs_chars);
       return (EXECUTION_FAILURE);
     }
 
-- 
2.45.1




reply via email to

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