Patch 8.2.3427
Problem:    Double free when list is copied.
Solution:   Allocate the type when making a copy. (closes #8862)
            Clear the type for flattennew().  Avoid a memory leak when
            flattennew() fails.
Files:      src/list.c, src/testdir/test_vim9_builtin.vim


*** ../vim-8.2.3426/src/list.c  2021-09-09 22:30:48.128865561 +0200
--- src/list.c  2021-09-11 18:23:32.708762620 +0200
***************
*** 952,958 ****
--- 952,961 ----
  
            vimlist_remove(list, item, item);
            if (list_extend(list, item->li_tv.vval.v_list, next) == FAIL)
+           {
+               list_free_item(list, item);
                return;
+           }
            clear_tv(&item->li_tv);
            tofree = item;
  
***************
*** 1023,1028 ****
--- 1026,1034 ----
        rettv->vval.v_list = l;
        if (l == NULL)
            return;
+       // The type will change.
+       free_type(l->lv_type);
+       l->lv_type = NULL;
      }
      else
      {
***************
*** 1217,1223 ****
      copy = list_alloc();
      if (copy != NULL)
      {
!       copy->lv_type = orig->lv_type;
        if (copyID != 0)
        {
            // Do this before adding the items, because one of the items may
--- 1223,1229 ----
      copy = list_alloc();
      if (copy != NULL)
      {
!       copy->lv_type = alloc_type(orig->lv_type);
        if (copyID != 0)
        {
            // Do this before adding the items, because one of the items may
*** ../vim-8.2.3426/src/testdir/test_vim9_builtin.vim   2021-09-08 
14:57:38.237188053 +0200
--- src/testdir/test_vim9_builtin.vim   2021-09-11 18:24:49.288588747 +0200
***************
*** 1090,1095 ****
--- 1090,1102 ----
    CheckDefAndScriptFailure2(['findfile("a", "b", "c")'], 'E1013: Argument 3: 
type mismatch, expected number but got string', 'E1210: Number required for 
argument 3')
  enddef
  
+ def Test_flatten()
+   var lines =<< trim END
+       echo flatten([1, 2, 3])
+   END
+   CheckDefAndScriptFailure(lines, 'E1158:')
+ enddef
+ 
  def Test_flattennew()
    var lines =<< trim END
        var l = [1, [2, [3, 4]], 5]
***************
*** 1098,1110 ****
  
        call assert_equal([1, 2, [3, 4], 5], flattennew(l, 1))
        call assert_equal([1, [2, [3, 4]], 5], l)
    END
    CheckDefAndScriptSuccess(lines)
  
-   lines =<< trim END
-       echo flatten([1, 2, 3])
-   END
-   CheckDefAndScriptFailure(lines, 'E1158:')
    CheckDefAndScriptFailure2(['flattennew({})'], 'E1013: Argument 1: type 
mismatch, expected list<any> but got dict<unknown>', 'E1211: List required for 
argument 1')
    CheckDefAndScriptFailure2(['flattennew([], "1")'], 'E1013: Argument 2: type 
mismatch, expected number but got string', 'E1210: Number required for argument 
2')
  enddef
--- 1105,1116 ----
  
        call assert_equal([1, 2, [3, 4], 5], flattennew(l, 1))
        call assert_equal([1, [2, [3, 4]], 5], l)
+ 
+       var ll: list<list<string>> = [['a', 'b', 'c']]
+       assert_equal(['a', 'b', 'c'], ll->flattennew())
    END
    CheckDefAndScriptSuccess(lines)
  
    CheckDefAndScriptFailure2(['flattennew({})'], 'E1013: Argument 1: type 
mismatch, expected list<any> but got dict<unknown>', 'E1211: List required for 
argument 1')
    CheckDefAndScriptFailure2(['flattennew([], "1")'], 'E1013: Argument 2: type 
mismatch, expected number but got string', 'E1210: Number required for argument 
2')
  enddef
*** ../vim-8.2.3426/src/version.c       2021-09-11 15:06:40.484475113 +0200
--- src/version.c       2021-09-11 17:33:52.608969229 +0200
***************
*** 757,758 ****
--- 757,760 ----
  {   /* Add new patch number below this line */
+ /**/
+     3427,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
27. You refer to your age as 3.x.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202109111821.18BIL5G5669674%40masaka.moolenaar.net.

Raspunde prin e-mail lui