aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2019-08-22 00:49:33 -0400
committerDaniel Hahler <git@thequod.de>2019-08-22 06:49:33 +0200
commited28668392e450bf22fe97e0581a63135498b8c0 (patch)
treef2590a2bfdbb9e54e386d9f6fa913b9deccf87b8 /src
parentbb50eadc84a4d095b1739ad31720fafe7bca6d0f (diff)
downloadrneovim-ed28668392e450bf22fe97e0581a63135498b8c0.tar.gz
rneovim-ed28668392e450bf22fe97e0581a63135498b8c0.tar.bz2
rneovim-ed28668392e450bf22fe97e0581a63135498b8c0.zip
vim-patch:8.1.1897: may free memory twice when out of memory (#10827)
Problem: May free memory twice when out of memory. Solution: Check that backslash_halve_save() returns a different pointer. (Dominique Pelle, closes vim/vim#4847) https://github.com/vim/vim/commit/f1552d07d715b437d941659479942c2543b02bd4
Diffstat (limited to 'src')
-rw-r--r--src/nvim/charset.c3
-rw-r--r--src/nvim/ex_getln.c28
-rw-r--r--src/nvim/os/env.c1
-rw-r--r--src/nvim/path.c5
4 files changed, 21 insertions, 16 deletions
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index 9060a0de82..1dec0beeee 100644
--- a/src/nvim/charset.c
+++ b/src/nvim/charset.c
@@ -1900,7 +1900,8 @@ void backslash_halve(char_u *p)
/// @param p
///
/// @return String with the number of backslashes halved.
-char_u* backslash_halve_save(char_u *p)
+char_u *backslash_halve_save(const char_u *p)
+ FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET
{
// TODO(philix): simplify and improve backslash_halve_save algorithm
char_u *res = vim_strsave(p);
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 17292dfde1..e8d650accf 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -4212,24 +4212,24 @@ static int showmatches(expand_T *xp, int wildmenu)
|| xp->xp_context == EXPAND_BUFFERS) {
/* highlight directories */
if (xp->xp_numfiles != -1) {
- char_u *halved_slash;
- char_u *exp_path;
-
- /* Expansion was done before and special characters
- * were escaped, need to halve backslashes. Also
- * $HOME has been replaced with ~/. */
- exp_path = expand_env_save_opt(files_found[k], TRUE);
- halved_slash = backslash_halve_save(
- exp_path != NULL ? exp_path : files_found[k]);
+ // Expansion was done before and special characters
+ // were escaped, need to halve backslashes. Also
+ // $HOME has been replaced with ~/.
+ char_u *exp_path = expand_env_save_opt(files_found[k], true);
+ char_u *path = exp_path != NULL ? exp_path : files_found[k];
+ char_u *halved_slash = backslash_halve_save(path);
j = os_isdir(halved_slash);
xfree(exp_path);
- xfree(halved_slash);
- } else
- /* Expansion was done here, file names are literal. */
+ if (halved_slash != path) {
+ xfree(halved_slash);
+ }
+ } else {
+ // Expansion was done here, file names are literal.
j = os_isdir(files_found[k]);
- if (showtail)
+ }
+ if (showtail) {
p = L_SHOWFILE(k);
- else {
+ } else {
home_replace(NULL, files_found[k], NameBuff, MAXPATHL,
TRUE);
p = NameBuff;
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c
index 669475fa72..f5dbf0694e 100644
--- a/src/nvim/os/env.c
+++ b/src/nvim/os/env.c
@@ -412,6 +412,7 @@ void expand_env_esc(char_u *restrict srcp,
bool esc,
bool one,
char_u *prefix)
+ FUNC_ATTR_NONNULL_ARG(1, 2)
{
char_u *tail;
char_u *var;
diff --git a/src/nvim/path.c b/src/nvim/path.c
index a58d57d566..1c787e3a1d 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -1262,7 +1262,10 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file,
} else {
addfile(&ga, t, flags);
}
- xfree(t);
+
+ if (t != p) {
+ xfree(t);
+ }
}
if (did_expand_in_path && !GA_EMPTY(&ga) && (flags & EW_PATH))