Mirror of the Vim source from https://github.com/vim/vim
Revision | 6c32d1072f82af0cd0e963011ccb57dc82916ed4 (tree) |
---|---|
Time | 2022-12-20 02:00:04 |
Author | Bram Moolenaar <Bram@vim....> |
Commiter | Bram Moolenaar |
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
@@ -342,6 +342,11 @@ | ||
342 | 342 | call assert_fails('com DoCmd :', 'E174:') |
343 | 343 | comclear |
344 | 344 | 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:') | |
345 | 350 | endfunc |
346 | 351 | |
347 | 352 | func CustomComplete(A, L, P) |
@@ -1167,7 +1167,7 @@ | ||
1167 | 1167 | end = skiptowhite(p); |
1168 | 1168 | if (uc_scan_attr(p, end - p, &argt, &def, &flags, &compl, |
1169 | 1169 | &compl_arg, &addr_type_arg) == FAIL) |
1170 | - return; | |
1170 | + goto theend; | |
1171 | 1171 | p = skipwhite(end); |
1172 | 1172 | } |
1173 | 1173 |
@@ -1179,7 +1179,7 @@ | ||
1179 | 1179 | if (!ends_excmd2(eap->arg, p) && !VIM_ISWHITE(*p)) |
1180 | 1180 | { |
1181 | 1181 | emsg(_(e_invalid_command_name)); |
1182 | - return; | |
1182 | + goto theend; | |
1183 | 1183 | } |
1184 | 1184 | end = p; |
1185 | 1185 | name_len = (int)(end - name); |
@@ -1188,13 +1188,19 @@ | ||
1188 | 1188 | // we are listing commands |
1189 | 1189 | p = skipwhite(end); |
1190 | 1190 | if (!has_attr && ends_excmd2(eap->arg, p)) |
1191 | + { | |
1191 | 1192 | uc_list(name, end - name); |
1193 | + } | |
1192 | 1194 | else if (!ASCII_ISUPPER(*name)) |
1195 | + { | |
1193 | 1196 | emsg(_(e_user_defined_commands_must_start_with_an_uppercase_letter)); |
1197 | + } | |
1194 | 1198 | else if ((name_len == 1 && *name == 'X') |
1195 | 1199 | || (name_len <= 4 |
1196 | 1200 | && STRNCMP(name, "Next", name_len > 4 ? 4 : name_len) == 0)) |
1201 | + { | |
1197 | 1202 | emsg(_(e_reserved_name_cannot_be_used_for_user_defined_command)); |
1203 | + } | |
1198 | 1204 | else if (compl > 0 && (argt & EX_EXTRA) == 0) |
1199 | 1205 | { |
1200 | 1206 | // Some plugins rely on silently ignoring the mistake, only make this |
@@ -1215,7 +1221,12 @@ | ||
1215 | 1221 | uc_add_command(name, end - name, p, argt, def, flags, compl, compl_arg, |
1216 | 1222 | addr_type_arg, eap->forceit); |
1217 | 1223 | vim_free(tofree); |
1224 | + | |
1225 | + return; // success | |
1218 | 1226 | } |
1227 | + | |
1228 | +theend: | |
1229 | + vim_free(compl_arg); | |
1219 | 1230 | } |
1220 | 1231 | |
1221 | 1232 | /* |
@@ -696,6 +696,8 @@ | ||
696 | 696 | static int included_patches[] = |
697 | 697 | { /* Add new patch number below this line */ |
698 | 698 | /**/ |
699 | + 1079, | |
700 | +/**/ | |
699 | 701 | 1078, |
700 | 702 | /**/ |
701 | 703 | 1077, |