To: vim_dev@googlegroups.com Subject: Patch 7.4.2197 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.2197 Problem: All functions are freed on exit, which may hide leaks. Solution: Only free named functions, not reference counted ones. Files: src/userfunc.c *** ../vim-7.4.2196/src/userfunc.c 2016-08-01 22:49:18.065145186 +0200 --- src/userfunc.c 2016-08-11 22:15:52.452703436 +0200 *************** *** 1099,1120 **** vim_free(fp); } #if defined(EXITFREE) || defined(PROTO) void free_all_functions(void) { hashitem_T *hi; /* Need to start all over every time, because func_free() may change the * hash table. */ ! while (func_hashtab.ht_used > 0) ! for (hi = func_hashtab.ht_array; ; ++hi) if (!HASHITEM_EMPTY(hi)) { ! func_free(HI2UF(hi), TRUE); ! break; } ! hash_clear(&func_hashtab); } #endif --- 1099,1151 ---- vim_free(fp); } + /* + * There are two kinds of function names: + * 1. ordinary names, function defined with :function + * 2. numbered functions and lambdas + * For the first we only count the name stored in func_hashtab as a reference, + * using function() does not count as a reference, because the function is + * looked up by name. + */ + static int + func_name_refcount(char_u *name) + { + return isdigit(*name) || *name == '<'; + } + #if defined(EXITFREE) || defined(PROTO) void free_all_functions(void) { hashitem_T *hi; + ufunc_T *fp; + long_u skipped = 0; + long_u todo; /* Need to start all over every time, because func_free() may change the * hash table. */ ! while (func_hashtab.ht_used > skipped) ! { ! todo = func_hashtab.ht_used; ! for (hi = func_hashtab.ht_array; todo > 0; ++hi) if (!HASHITEM_EMPTY(hi)) { ! --todo; ! /* Only free functions that are not refcounted, those are ! * supposed to be freed when no longer referenced. */ ! fp = HI2UF(hi); ! if (func_name_refcount(fp->uf_name)) ! ++skipped; ! else ! { ! func_free(fp, TRUE); ! skipped = 0; ! break; ! } } ! } ! if (skipped == 0) ! hash_clear(&func_hashtab); } #endif *************** *** 1669,1688 **** } /* - * There are two kinds of function names: - * 1. ordinary names, function defined with :function - * 2. numbered functions and lambdas - * For the first we only count the name stored in func_hashtab as a reference, - * using function() does not count as a reference, because the function is - * looked up by name. - */ - static int - func_name_refcount(char_u *name) - { - return isdigit(*name) || *name == '<'; - } - - /* * ":function" */ void --- 1700,1705 ---- *** ../vim-7.4.2196/src/version.c 2016-08-10 23:02:42.499155800 +0200 --- src/version.c 2016-08-11 22:20:49.922041422 +0200 *************** *** 765,766 **** --- 765,768 ---- { /* Add new patch number below this line */ + /**/ + 2197, /**/ -- hundred-and-one symptoms of being an internet addict: 5. You find yourself brainstorming for new subjects to search. /// Bram Moolenaar -- Bram@Moolenaar.net -- 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 ///