]> granicus.if.org Git - vim/commitdiff
patch 8.2.4782: accessing freed memory v8.2.4782
authorBram Moolenaar <Bram@vim.org>
Mon, 18 Apr 2022 14:21:17 +0000 (15:21 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 18 Apr 2022 14:21:17 +0000 (15:21 +0100)
Problem:    Accessing freed memory.
Solution:   Clear evalarg after checking for trailing characters.
            (issue #10218)

src/testdir/test_lambda.vim
src/userfunc.c
src/version.c

index 8d06e5973c182781aebb2132ab045d0d790ea52f..77266299e999ebbe60429875b28cb325f0d52bd0 100644 (file)
@@ -1,6 +1,7 @@
 " Test for lambda and closure
 
 source check.vim
+import './vim9.vim' as v9
 
 func Test_lambda_feature()
   call assert_equal(1, has('lambda'))
@@ -54,6 +55,21 @@ func Test_lambda_with_timer()
   call assert_true(s:n > m)
 endfunc
 
+func Test_lambda_vim9cmd_linebreak()
+  CheckFeature timers
+
+  let lines =<< trim END
+      vim9cmd call timer_start(10, (x) => {
+          # comment
+          g:result = 'done'
+         })
+  END
+  call v9.CheckScriptSuccess(lines)
+  sleep 50m
+  call assert_equal('done', g:result)
+  unlet g:result
+endfunc
+
 func Test_lambda_with_partial()
   let l:Cb = function({... -> ['zero', a:1, a:2, a:3]}, ['one', 'two'])
   call assert_equal(['zero', 'one', 'two', 'three'], l:Cb('three'))
index 155c4ff1c543ef25fc25a23452e2da1aec5e711c..f3ba7719ce8d0d0c103c2e0208ca59ff97303c6c 100644 (file)
@@ -5529,7 +5529,6 @@ ex_call(exarg_T *eap)
     }
     if (eap->skip)
        --emsg_skip;
-    clear_evalarg(&evalarg, eap);
 
     // When inside :try we need to check for following "| catch" or "| endtry".
     // Not when there was an error, but do check if an exception was thrown.
@@ -5549,6 +5548,8 @@ ex_call(exarg_T *eap)
        else
            set_nextcmd(eap, arg);
     }
+    // Must be after using "arg", it may point into memory cleared here.
+    clear_evalarg(&evalarg, eap);
 
 end:
     dict_unref(fudi.fd_dict);
index eb05f882235af4bd7a4d5b9a467592c786e4dcb9..7f792d250deae4fe3919946787c23de776270eb9 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4782,
 /**/
     4781,
 /**/