Patch 8.2.0882
Problem: Leaking memory when using reduce().
Solution: Free the intermediate value.
Files: src/list.c
*** ../vim-8.2.0881/src/list.c 2020-06-01 18:39:14.040317510 +0200
--- src/list.c 2020-06-01 20:09:20.439982833 +0200
***************
*** 2311,2317 ****
void
f_reduce(typval_T *argvars, typval_T *rettv)
{
! typval_T accum;
char_u *func_name;
partial_T *partial = NULL;
funcexe_T funcexe;
--- 2311,2317 ----
void
f_reduce(typval_T *argvars, typval_T *rettv)
{
! typval_T initial;
char_u *func_name;
partial_T *partial = NULL;
funcexe_T funcexe;
***************
*** 2343,2348 ****
--- 2343,2349 ----
{
list_T *l = argvars[0].vval.v_list;
listitem_T *li = NULL;
+ int r;
CHECK_LIST_MATERIALIZE(l);
if (argvars[2].v_type == VAR_UNKNOWN)
***************
*** 2352,2375 ****
semsg(_(e_reduceempty), "List");
return;
}
! accum = l->lv_first->li_tv;
li = l->lv_first->li_next;
}
else
{
! accum = argvars[2];
if (l != NULL)
li = l->lv_first;
}
! copy_tv(&accum, rettv);
for ( ; li != NULL; li = li->li_next)
{
! argv[0] = accum;
argv[1] = li->li_tv;
! if (call_func(func_name, -1, rettv, 2, argv, &funcexe) == FAIL)
return;
- accum = *rettv;
}
}
else
--- 2353,2378 ----
semsg(_(e_reduceempty), "List");
return;
}
! initial = l->lv_first->li_tv;
li = l->lv_first->li_next;
}
else
{
! initial = argvars[2];
if (l != NULL)
li = l->lv_first;
}
! copy_tv(&initial, rettv);
for ( ; li != NULL; li = li->li_next)
{
! argv[0] = *rettv;
argv[1] = li->li_tv;
! rettv->v_type = VAR_UNKNOWN;
! r = call_func(func_name, -1, rettv, 2, argv, &funcexe);
! clear_tv(&argv[0]);
! if (r == FAIL)
return;
}
}
else
***************
*** 2384,2410 ****
semsg(_(e_reduceempty), "Blob");
return;
}
! accum.v_type = VAR_NUMBER;
! accum.vval.v_number = blob_get(b, 0);
i = 1;
}
else
{
! accum = argvars[2];
i = 0;
}
! copy_tv(&accum, rettv);
if (b != NULL)
{
for ( ; i < b->bv_ga.ga_len; i++)
{
! argv[0] = accum;
argv[1].v_type = VAR_NUMBER;
argv[1].vval.v_number = blob_get(b, i);
if (call_func(func_name, -1, rettv, 2, argv, &funcexe) == FAIL)
return;
- accum = *rettv;
}
}
}
--- 2387,2417 ----
semsg(_(e_reduceempty), "Blob");
return;
}
! initial.v_type = VAR_NUMBER;
! initial.vval.v_number = blob_get(b, 0);
i = 1;
}
+ else if (argvars[2].v_type != VAR_NUMBER)
+ {
+ emsg(_(e_number_exp));
+ return;
+ }
else
{
! initial = argvars[2];
i = 0;
}
! copy_tv(&initial, rettv);
if (b != NULL)
{
for ( ; i < b->bv_ga.ga_len; i++)
{
! argv[0] = *rettv;
argv[1].v_type = VAR_NUMBER;
argv[1].vval.v_number = blob_get(b, i);
if (call_func(func_name, -1, rettv, 2, argv, &funcexe) == FAIL)
return;
}
}
}
*** ../vim-8.2.0881/src/version.c 2020-06-01 19:14:09.050505748 +0200
--- src/version.c 2020-06-01 20:10:05.639865786 +0200
***************
*** 748,749 ****
--- 748,751 ----
{ /* Add new patch number below this line */
+ /**/
+ 882,
/**/
--
hundred-and-one symptoms of being an internet addict:
248. You sign your letters with your e-mail address instead of your name.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ 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/202006011811.051IBV0t035605%40masaka.moolenaar.net.