bb9a7e
From cc978a670597afc3251baca3a7db553f36946c22 Mon Sep 17 00:00:00 2001
bb9a7e
From: Chet Ramey <chet.ramey@case.edu>
bb9a7e
Date: Tue, 4 May 2021 14:29:06 -0400
bb9a7e
Subject: [PATCH] Bash-5.1 patch 5: fix memory leaks in compound array
bb9a7e
 assignments
bb9a7e
bb9a7e
---
bb9a7e
 arrayfunc.c  | 11 +++--------
bb9a7e
 patchlevel.h |  2 +-
bb9a7e
 subst.c      |  2 ++
bb9a7e
 3 files changed, 6 insertions(+), 9 deletions(-)
bb9a7e
bb9a7e
diff --git a/arrayfunc.c b/arrayfunc.c
bb9a7e
index 8231ba1e..9338dfc7 100644
bb9a7e
--- a/arrayfunc.c
bb9a7e
+++ b/arrayfunc.c
bb9a7e
@@ -564,12 +564,9 @@ assign_assoc_from_kvlist (var, nlist, h, flags)
bb9a7e
 {
bb9a7e
   WORD_LIST *list;
bb9a7e
   char *akey, *aval, *k, *v;
bb9a7e
-  int free_aval;
bb9a7e
 
bb9a7e
   for (list = nlist; list; list = list->next)
bb9a7e
     {
bb9a7e
-      free_aval = 0;
bb9a7e
-
bb9a7e
       k = list->word->word;
bb9a7e
       v = list->next ? list->next->word->word : 0;
bb9a7e
 
bb9a7e
@@ -577,24 +574,22 @@ assign_assoc_from_kvlist (var, nlist, h, flags)
bb9a7e
         list = list->next;
bb9a7e
 
bb9a7e
       akey = expand_assignment_string_to_string (k, 0);
bb9a7e
-      aval = expand_assignment_string_to_string (v, 0);
bb9a7e
-
bb9a7e
       if (akey == 0 || *akey == 0)
bb9a7e
 	{
bb9a7e
 	  err_badarraysub (k);
bb9a7e
 	  FREE (akey);
bb9a7e
 	  continue;
bb9a7e
 	}	      
bb9a7e
+
bb9a7e
+      aval = expand_assignment_string_to_string (v, 0);
bb9a7e
       if (aval == 0)
bb9a7e
 	{
bb9a7e
 	  aval = (char *)xmalloc (1);
bb9a7e
 	  aval[0] = '\0';	/* like do_assignment_internal */
bb9a7e
-	  free_aval = 1;
bb9a7e
 	}
bb9a7e
 
bb9a7e
       bind_assoc_var_internal (var, h, akey, aval, flags);
bb9a7e
-      if (free_aval)
bb9a7e
-	free (aval);
bb9a7e
+      free (aval);
bb9a7e
     }
bb9a7e
 }
bb9a7e
 
bb9a7e
diff --git a/patchlevel.h b/patchlevel.h
bb9a7e
index e1429c24..c7f39aec 100644
bb9a7e
--- a/patchlevel.h
bb9a7e
+++ b/patchlevel.h
bb9a7e
@@ -25,6 +25,6 @@
bb9a7e
    regexp `^#define[ 	]*PATCHLEVEL', since that's what support/mkversion.sh
bb9a7e
    looks for to find the patch level (for the sccs version string). */
bb9a7e
 
bb9a7e
-#define PATCHLEVEL 4
bb9a7e
+#define PATCHLEVEL 5
bb9a7e
 
bb9a7e
 #endif /* _PATCHLEVEL_H_ */
bb9a7e
diff --git a/subst.c b/subst.c
bb9a7e
index 6132316a..1d24188e 100644
bb9a7e
--- a/subst.c
bb9a7e
+++ b/subst.c
bb9a7e
@@ -11673,6 +11673,8 @@ expand_compound_assignment_word (tlist, flags)
bb9a7e
   free (value);
bb9a7e
 
bb9a7e
   value = string_list (l);
bb9a7e
+  dispose_words (l);
bb9a7e
+
bb9a7e
   wlen = STRLEN (value);
bb9a7e
 
bb9a7e
   /* Now, let's rebuild the string */
bb9a7e
-- 
bb9a7e
2.29.2
bb9a7e