mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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)
f1552d07d7
This commit is contained in:
parent
bb50eadc84
commit
ed28668392
@ -1900,7 +1900,8 @@ void backslash_halve(char_u *p)
|
|||||||
/// @param p
|
/// @param p
|
||||||
///
|
///
|
||||||
/// @return String with the number of backslashes halved.
|
/// @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
|
// TODO(philix): simplify and improve backslash_halve_save algorithm
|
||||||
char_u *res = vim_strsave(p);
|
char_u *res = vim_strsave(p);
|
||||||
|
@ -4212,24 +4212,24 @@ static int showmatches(expand_T *xp, int wildmenu)
|
|||||||
|| xp->xp_context == EXPAND_BUFFERS) {
|
|| xp->xp_context == EXPAND_BUFFERS) {
|
||||||
/* highlight directories */
|
/* highlight directories */
|
||||||
if (xp->xp_numfiles != -1) {
|
if (xp->xp_numfiles != -1) {
|
||||||
char_u *halved_slash;
|
// Expansion was done before and special characters
|
||||||
char_u *exp_path;
|
// were escaped, need to halve backslashes. Also
|
||||||
|
// $HOME has been replaced with ~/.
|
||||||
/* Expansion was done before and special characters
|
char_u *exp_path = expand_env_save_opt(files_found[k], true);
|
||||||
* were escaped, need to halve backslashes. Also
|
char_u *path = exp_path != NULL ? exp_path : files_found[k];
|
||||||
* $HOME has been replaced with ~/. */
|
char_u *halved_slash = backslash_halve_save(path);
|
||||||
exp_path = expand_env_save_opt(files_found[k], TRUE);
|
|
||||||
halved_slash = backslash_halve_save(
|
|
||||||
exp_path != NULL ? exp_path : files_found[k]);
|
|
||||||
j = os_isdir(halved_slash);
|
j = os_isdir(halved_slash);
|
||||||
xfree(exp_path);
|
xfree(exp_path);
|
||||||
xfree(halved_slash);
|
if (halved_slash != path) {
|
||||||
} else
|
xfree(halved_slash);
|
||||||
/* Expansion was done here, file names are literal. */
|
}
|
||||||
|
} else {
|
||||||
|
// Expansion was done here, file names are literal.
|
||||||
j = os_isdir(files_found[k]);
|
j = os_isdir(files_found[k]);
|
||||||
if (showtail)
|
}
|
||||||
|
if (showtail) {
|
||||||
p = L_SHOWFILE(k);
|
p = L_SHOWFILE(k);
|
||||||
else {
|
} else {
|
||||||
home_replace(NULL, files_found[k], NameBuff, MAXPATHL,
|
home_replace(NULL, files_found[k], NameBuff, MAXPATHL,
|
||||||
TRUE);
|
TRUE);
|
||||||
p = NameBuff;
|
p = NameBuff;
|
||||||
|
@ -412,6 +412,7 @@ void expand_env_esc(char_u *restrict srcp,
|
|||||||
bool esc,
|
bool esc,
|
||||||
bool one,
|
bool one,
|
||||||
char_u *prefix)
|
char_u *prefix)
|
||||||
|
FUNC_ATTR_NONNULL_ARG(1, 2)
|
||||||
{
|
{
|
||||||
char_u *tail;
|
char_u *tail;
|
||||||
char_u *var;
|
char_u *var;
|
||||||
|
@ -1262,7 +1262,10 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file,
|
|||||||
} else {
|
} else {
|
||||||
addfile(&ga, t, flags);
|
addfile(&ga, t, flags);
|
||||||
}
|
}
|
||||||
xfree(t);
|
|
||||||
|
if (t != p) {
|
||||||
|
xfree(t);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (did_expand_in_path && !GA_EMPTY(&ga) && (flags & EW_PATH))
|
if (did_expand_in_path && !GA_EMPTY(&ga) && (flags & EW_PATH))
|
||||||
|
Loading…
Reference in New Issue
Block a user