• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revision6c32d1072f82af0cd0e963011ccb57dc82916ed4 (tree)
Time2022-12-20 02:00:04
AuthorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 9.0.1079: leaking memory when defining a user command fails

Commit: https://github.com/vim/vim/commit/33e543038b84af7557ab9ecff500fc4ab98dd2a3
Author: zeertzjq <zeertzjq@outlook.com>
Date: Mon Dec 19 16:49:27 2022 +0000

patch 9.0.1079: leaking memory when defining a user command fails
Problem: Leaking memory when defining a user command fails.
Solution: Free "compl_arg" when needed. (closes https://github.com/vim/vim/issues/11726)

Change Summary

Incremental Difference

diff -r 6b30ccb7cbe9 -r 6c32d1072f82 src/testdir/test_usercommands.vim
--- a/src/testdir/test_usercommands.vim Mon Dec 19 17:00:06 2022 +0100
+++ b/src/testdir/test_usercommands.vim Mon Dec 19 18:00:04 2022 +0100
@@ -342,6 +342,11 @@
342342 call assert_fails('com DoCmd :', 'E174:')
343343 comclear
344344 call assert_fails('delcom DoCmd', 'E184:')
345+
346+ " These used to leak memory
347+ call assert_fails('com! -complete=custom,CustomComplete _ :', 'E182:')
348+ call assert_fails('com! -complete=custom,CustomComplete docmd :', 'E183:')
349+ call assert_fails('com! -complete=custom,CustomComplete -xxx DoCmd :', 'E181:')
345350 endfunc
346351
347352 func CustomComplete(A, L, P)
diff -r 6b30ccb7cbe9 -r 6c32d1072f82 src/usercmd.c
--- a/src/usercmd.c Mon Dec 19 17:00:06 2022 +0100
+++ b/src/usercmd.c Mon Dec 19 18:00:04 2022 +0100
@@ -1167,7 +1167,7 @@
11671167 end = skiptowhite(p);
11681168 if (uc_scan_attr(p, end - p, &argt, &def, &flags, &compl,
11691169 &compl_arg, &addr_type_arg) == FAIL)
1170- return;
1170+ goto theend;
11711171 p = skipwhite(end);
11721172 }
11731173
@@ -1179,7 +1179,7 @@
11791179 if (!ends_excmd2(eap->arg, p) && !VIM_ISWHITE(*p))
11801180 {
11811181 emsg(_(e_invalid_command_name));
1182- return;
1182+ goto theend;
11831183 }
11841184 end = p;
11851185 name_len = (int)(end - name);
@@ -1188,13 +1188,19 @@
11881188 // we are listing commands
11891189 p = skipwhite(end);
11901190 if (!has_attr && ends_excmd2(eap->arg, p))
1191+ {
11911192 uc_list(name, end - name);
1193+ }
11921194 else if (!ASCII_ISUPPER(*name))
1195+ {
11931196 emsg(_(e_user_defined_commands_must_start_with_an_uppercase_letter));
1197+ }
11941198 else if ((name_len == 1 && *name == 'X')
11951199 || (name_len <= 4
11961200 && STRNCMP(name, "Next", name_len > 4 ? 4 : name_len) == 0))
1201+ {
11971202 emsg(_(e_reserved_name_cannot_be_used_for_user_defined_command));
1203+ }
11981204 else if (compl > 0 && (argt & EX_EXTRA) == 0)
11991205 {
12001206 // Some plugins rely on silently ignoring the mistake, only make this
@@ -1215,7 +1221,12 @@
12151221 uc_add_command(name, end - name, p, argt, def, flags, compl, compl_arg,
12161222 addr_type_arg, eap->forceit);
12171223 vim_free(tofree);
1224+
1225+ return; // success
12181226 }
1227+
1228+theend:
1229+ vim_free(compl_arg);
12191230 }
12201231
12211232 /*
diff -r 6b30ccb7cbe9 -r 6c32d1072f82 src/version.c
--- a/src/version.c Mon Dec 19 17:00:06 2022 +0100
+++ b/src/version.c Mon Dec 19 18:00:04 2022 +0100
@@ -696,6 +696,8 @@
696696 static int included_patches[] =
697697 { /* Add new patch number below this line */
698698 /**/
699+ 1079,
700+/**/
699701 1078,
700702 /**/
701703 1077,
Show on old repository browser