]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
Bash-5.1 patch 5: fix memory leaks in compound array assignments
authorChet Ramey <chet.ramey@case.edu>
Tue, 4 May 2021 18:29:06 +0000 (14:29 -0400)
committerChet Ramey <chet.ramey@case.edu>
Tue, 4 May 2021 18:29:06 +0000 (14:29 -0400)
arrayfunc.c
patchlevel.h
subst.c

index 8231ba1eded7d704a4fc2067c24d9af4b59d07e4..9338dfc719605536f42b334285758e2238aabc4f 100644 (file)
@@ -564,12 +564,9 @@ assign_assoc_from_kvlist (var, nlist, h, flags)
 {
   WORD_LIST *list;
   char *akey, *aval, *k, *v;
-  int free_aval;
 
   for (list = nlist; list; list = list->next)
     {
-      free_aval = 0;
-
       k = list->word->word;
       v = list->next ? list->next->word->word : 0;
 
@@ -577,24 +574,22 @@ assign_assoc_from_kvlist (var, nlist, h, flags)
         list = list->next;
 
       akey = expand_assignment_string_to_string (k, 0);
-      aval = expand_assignment_string_to_string (v, 0);
-
       if (akey == 0 || *akey == 0)
        {
          err_badarraysub (k);
          FREE (akey);
          continue;
        }             
+
+      aval = expand_assignment_string_to_string (v, 0);
       if (aval == 0)
        {
          aval = (char *)xmalloc (1);
          aval[0] = '\0';       /* like do_assignment_internal */
-         free_aval = 1;
        }
 
       bind_assoc_var_internal (var, h, akey, aval, flags);
-      if (free_aval)
-       free (aval);
+      free (aval);
     }
 }
 
index e1429c245ffb845f2c7ae586bc54b86f5af9d038..c7f39aec1faeb1c41bdcdc10c054a615e9661ff5 100644 (file)
@@ -25,6 +25,6 @@
    regexp `^#define[   ]*PATCHLEVEL', since that's what support/mkversion.sh
    looks for to find the patch level (for the sccs version string). */
 
-#define PATCHLEVEL 4
+#define PATCHLEVEL 5
 
 #endif /* _PATCHLEVEL_H_ */
diff --git a/subst.c b/subst.c
index 6132316a5ce0b774727b565b373f68b5a2562ea4..1d24188e5ec898f5463547ca5e7f08f6fb998a65 100644 (file)
--- a/subst.c
+++ b/subst.c
@@ -11673,6 +11673,8 @@ expand_compound_assignment_word (tlist, flags)
   free (value);
 
   value = string_list (l);
+  dispose_words (l);
+
   wlen = STRLEN (value);
 
   /* Now, let's rebuild the string */