]> granicus.if.org Git - vim/commitdiff
patch 8.2.3059: Vim9: memory leak when using lambda v8.2.3059
authorBram Moolenaar <Bram@vim.org>
Sat, 26 Jun 2021 20:17:35 +0000 (22:17 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 26 Jun 2021 20:17:35 +0000 (22:17 +0200)
Problem:    Vim9: memory leak when using lambda.
Solution:   Do not store the default value strings when skipping.

src/userfunc.c
src/version.c

index 3321f089c0ab26a365bfc1b769ba551835df547f..c8d08bb45cfe1e49de853609ab2920c02006e026 100644 (file)
@@ -198,7 +198,7 @@ get_function_args(
        ga_init2(newargs, (int)sizeof(char_u *), 3);
     if (argtypes != NULL)
        ga_init2(argtypes, (int)sizeof(char_u *), 3);
-    if (default_args != NULL)
+    if (!skip && default_args != NULL)
        ga_init2(default_args, (int)sizeof(char_u *), 3);
 
     if (varargs != NULL)
@@ -289,24 +289,27 @@ get_function_args(
                expr = p;
                if (eval1(&p, &rettv, NULL) != FAIL)
                {
-                   if (ga_grow(default_args, 1) == FAIL)
-                       goto err_ret;
-
-                   // trim trailing whitespace
-                   while (p > expr && VIM_ISWHITE(p[-1]))
-                       p--;
-                   c = *p;
-                   *p = NUL;
-                   expr = vim_strsave(expr);
-                   if (expr == NULL)
+                   if (!skip)
                    {
+                       if (ga_grow(default_args, 1) == FAIL)
+                           goto err_ret;
+
+                       // trim trailing whitespace
+                       while (p > expr && VIM_ISWHITE(p[-1]))
+                           p--;
+                       c = *p;
+                       *p = NUL;
+                       expr = vim_strsave(expr);
+                       if (expr == NULL)
+                       {
+                           *p = c;
+                           goto err_ret;
+                       }
+                       ((char_u **)(default_args->ga_data))
+                                                [default_args->ga_len] = expr;
+                       default_args->ga_len++;
                        *p = c;
-                       goto err_ret;
                    }
-                   ((char_u **)(default_args->ga_data))
-                                                [default_args->ga_len] = expr;
-                   default_args->ga_len++;
-                   *p = c;
                }
                else
                    mustend = TRUE;
@@ -357,7 +360,7 @@ get_function_args(
 err_ret:
     if (newargs != NULL)
        ga_clear_strings(newargs);
-    if (default_args != NULL)
+    if (!skip && default_args != NULL)
        ga_clear_strings(default_args);
     return FAIL;
 }
index 59f84d446b9ccfdfbee9df582cd29e81821b32d1..7fbd6d0b18104b03cf7be19c0ae98cc97c59f4b4 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3059,
 /**/
     3058,
 /**/