To: vim_dev@googlegroups.com Subject: Patch 9.0.1079 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1079 Problem: Leaking memory when defining a user command fails. Solution: Free "compl_arg" when needed. (closes #11726) Files: src/usercmd.c, src/testdir/test_usercommands.vim *** ../vim-9.0.1078/src/usercmd.c 2022-11-13 23:30:02.419807434 +0000 --- src/usercmd.c 2022-12-19 16:48:50.338894648 +0000 *************** *** 1167,1173 **** end = skiptowhite(p); if (uc_scan_attr(p, end - p, &argt, &def, &flags, &compl, &compl_arg, &addr_type_arg) == FAIL) ! return; p = skipwhite(end); } --- 1167,1173 ---- end = skiptowhite(p); if (uc_scan_attr(p, end - p, &argt, &def, &flags, &compl, &compl_arg, &addr_type_arg) == FAIL) ! goto theend; p = skipwhite(end); } *************** *** 1179,1185 **** if (!ends_excmd2(eap->arg, p) && !VIM_ISWHITE(*p)) { emsg(_(e_invalid_command_name)); ! return; } end = p; name_len = (int)(end - name); --- 1179,1185 ---- if (!ends_excmd2(eap->arg, p) && !VIM_ISWHITE(*p)) { emsg(_(e_invalid_command_name)); ! goto theend; } end = p; name_len = (int)(end - name); *************** *** 1188,1200 **** --- 1188,1206 ---- // we are listing commands p = skipwhite(end); if (!has_attr && ends_excmd2(eap->arg, p)) + { uc_list(name, end - name); + } else if (!ASCII_ISUPPER(*name)) + { emsg(_(e_user_defined_commands_must_start_with_an_uppercase_letter)); + } else if ((name_len == 1 && *name == 'X') || (name_len <= 4 && STRNCMP(name, "Next", name_len > 4 ? 4 : name_len) == 0)) + { emsg(_(e_reserved_name_cannot_be_used_for_user_defined_command)); + } else if (compl > 0 && (argt & EX_EXTRA) == 0) { // Some plugins rely on silently ignoring the mistake, only make this *************** *** 1215,1221 **** --- 1221,1232 ---- uc_add_command(name, end - name, p, argt, def, flags, compl, compl_arg, addr_type_arg, eap->forceit); vim_free(tofree); + + return; // success } + + theend: + vim_free(compl_arg); } /* *** ../vim-9.0.1078/src/testdir/test_usercommands.vim 2022-11-13 23:30:02.423807434 +0000 --- src/testdir/test_usercommands.vim 2022-12-19 16:46:19.478947940 +0000 *************** *** 342,347 **** --- 342,352 ---- call assert_fails('com DoCmd :', 'E174:') comclear call assert_fails('delcom DoCmd', 'E184:') + + " These used to leak memory + call assert_fails('com! -complete=custom,CustomComplete _ :', 'E182:') + call assert_fails('com! -complete=custom,CustomComplete docmd :', 'E183:') + call assert_fails('com! -complete=custom,CustomComplete -xxx DoCmd :', 'E181:') endfunc func CustomComplete(A, L, P) *** ../vim-9.0.1078/src/version.c 2022-12-19 15:51:40.379943472 +0000 --- src/version.c 2022-12-19 16:47:36.486920619 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1079, /**/ -- `When any government, or any church for that matter, undertakes to say to its subjects, "This you may not read, this you must not see, this you are forbidden to know," the end result is tyranny and oppression no matter how holy the motives' -- Robert A Heinlein, "If this goes on --" /// 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 ///