nalika / rpms / bash

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