diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-08-21 12:54:18 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-08-21 12:54:18 +0200 |
commit | f1552d07d715b437d941659479942c2543b02bd4 (patch) | |
tree | 75f97a65490a0d0ac259eea2eda3c7ae2d2109a0 | |
parent | eaf35241197fc6b9ee9af993095bf5e6f35c8f1a (diff) | |
download | vim-git-f1552d07d715b437d941659479942c2543b02bd4.tar.gz |
patch 8.1.1897: may free memory twice when out of memoryv8.1.1897
Problem: May free memory twice when out of memory.
Solution: Check that backslash_halve_save() returns a different pointer.
(Dominique Pelle, closes #4847)
-rw-r--r-- | src/cmdexpand.c | 8 | ||||
-rw-r--r-- | src/misc1.c | 4 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 10 insertions, 4 deletions
diff --git a/src/cmdexpand.c b/src/cmdexpand.c index 1454fd2f5..59d84419c 100644 --- a/src/cmdexpand.c +++ b/src/cmdexpand.c @@ -646,17 +646,19 @@ showmatches(expand_T *xp, int wildmenu UNUSED) { char_u *halved_slash; char_u *exp_path; + char_u *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]); + path = exp_path != NULL ? exp_path : files_found[k]; + halved_slash = backslash_halve_save(path); j = mch_isdir(halved_slash != NULL ? halved_slash : files_found[k]); vim_free(exp_path); - vim_free(halved_slash); + if (halved_slash != path) + vim_free(halved_slash); } else // Expansion was done here, file names are literal. diff --git a/src/misc1.c b/src/misc1.c index 4884f6cb5..5f0a7b6c3 100644 --- a/src/misc1.c +++ b/src/misc1.c @@ -4086,7 +4086,9 @@ gen_expand_wildcards( addfile(&ga, t, flags | EW_DIR | EW_FILE); else addfile(&ga, t, flags); - vim_free(t); + + if (t != p) + vim_free(t); } #if defined(FEAT_SEARCHPATH) diff --git a/src/version.c b/src/version.c index 81e0d5a2d..14a9528bc 100644 --- a/src/version.c +++ b/src/version.c @@ -766,6 +766,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1897, +/**/ 1896, /**/ 1895, |