To: vim_dev@googlegroups.com Subject: Patch 8.2.2764 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2764 Problem: Memory leak when default function argument is allocated. Solution: Free the expression result. Files: src/userfunc.c, src/testdir/test_functions.vim *** ../vim-8.2.2763/src/userfunc.c 2021-04-12 22:02:32.308393464 +0200 --- src/userfunc.c 2021-04-14 17:00:25.589940213 +0200 *************** *** 2188,2193 **** --- 2188,2195 ---- int islambda = FALSE; char_u numbuf[NUMBUFLEN]; char_u *name; + typval_T *tv_to_free[MAX_FUNC_ARGS]; + int tv_to_free_len = 0; #ifdef FEAT_PROFILE profinfo_T profile_info; #endif *************** *** 2333,2338 **** --- 2335,2341 ---- if (isdefault) { char_u *default_expr = NULL; + def_rettv.v_type = VAR_NUMBER; def_rettv.vval.v_number = -1; *************** *** 2374,2379 **** --- 2377,2386 ---- v->di_tv = isdefault ? def_rettv : argvars[i]; v->di_tv.v_lock = VAR_FIXED; + if (isdefault) + // Need to free this later, no matter where it's stored. + tv_to_free[tv_to_free_len++] = &v->di_tv; + if (addlocal) { // Named arguments should be accessed without the "a:" prefix in *************** *** 2563,2568 **** --- 2570,2577 ---- did_emsg |= save_did_emsg; funcdepth_decrement(); + for (i = 0; i < tv_to_free_len; ++i) + clear_tv(tv_to_free[i]); cleanup_function_call(fc); } *** ../vim-8.2.2763/src/testdir/test_functions.vim 2021-03-22 19:37:02.545019774 +0100 --- src/testdir/test_functions.vim 2021-04-14 16:50:04.039459508 +0200 *************** *** 1497,1502 **** --- 1497,1503 ---- func Test_balloon_show() CheckFeature balloon_eval + " This won't do anything but must not crash either. call balloon_show('hi!') if !has('gui_running') *************** *** 2650,2653 **** --- 2651,2662 ---- call assert_fails('call browsedir("open", [])', 'E730:') endfunc + func HasDefault(msg = 'msg') + return a:msg + endfunc + + func Test_default_arg_value() + call assert_equal('msg', HasDefault()) + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.2763/src/version.c 2021-04-14 13:30:42.978156753 +0200 --- src/version.c 2021-04-14 17:06:09.133037053 +0200 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2764, /**/ -- From "know your smileys": :-* A big kiss! /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///