forked from aniani/vim
patch 8.1.1843: might be freeing memory that was not allocated
Problem: Might be freeing memory that was not allocated. Solution: Have next_fenc() set the fenc_alloced flag. (closes #4804)
This commit is contained in:
parent
9570aacdb8
commit
f077db2423
19
src/fileio.c
19
src/fileio.c
@ -27,7 +27,7 @@
|
|||||||
/* Is there any system that doesn't have access()? */
|
/* Is there any system that doesn't have access()? */
|
||||||
#define USE_MCH_ACCESS
|
#define USE_MCH_ACCESS
|
||||||
|
|
||||||
static char_u *next_fenc(char_u **pp);
|
static char_u *next_fenc(char_u **pp, int *alloced);
|
||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
static char_u *readfile_charconvert(char_u *fname, char_u *fenc, int *fdp);
|
static char_u *readfile_charconvert(char_u *fname, char_u *fenc, int *fdp);
|
||||||
#endif
|
#endif
|
||||||
@ -890,8 +890,7 @@ readfile(
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
fenc_next = p_fencs; /* try items in 'fileencodings' */
|
fenc_next = p_fencs; /* try items in 'fileencodings' */
|
||||||
fenc = next_fenc(&fenc_next);
|
fenc = next_fenc(&fenc_next, &fenc_alloced);
|
||||||
fenc_alloced = TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -994,8 +993,7 @@ retry:
|
|||||||
vim_free(fenc);
|
vim_free(fenc);
|
||||||
if (fenc_next != NULL)
|
if (fenc_next != NULL)
|
||||||
{
|
{
|
||||||
fenc = next_fenc(&fenc_next);
|
fenc = next_fenc(&fenc_next, &fenc_alloced);
|
||||||
fenc_alloced = (fenc_next != NULL);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2761,14 +2759,16 @@ set_forced_fenc(exarg_T *eap)
|
|||||||
* "pp" points to fenc_next. It's advanced to the next item.
|
* "pp" points to fenc_next. It's advanced to the next item.
|
||||||
* When there are no more items, an empty string is returned and *pp is set to
|
* When there are no more items, an empty string is returned and *pp is set to
|
||||||
* NULL.
|
* NULL.
|
||||||
* When *pp is not set to NULL, the result is in allocated memory.
|
* When *pp is not set to NULL, the result is in allocated memory and "alloced"
|
||||||
|
* is set to TRUE.
|
||||||
*/
|
*/
|
||||||
static char_u *
|
static char_u *
|
||||||
next_fenc(char_u **pp)
|
next_fenc(char_u **pp, int *alloced)
|
||||||
{
|
{
|
||||||
char_u *p;
|
char_u *p;
|
||||||
char_u *r;
|
char_u *r;
|
||||||
|
|
||||||
|
*alloced = FALSE;
|
||||||
if (**pp == NUL)
|
if (**pp == NUL)
|
||||||
{
|
{
|
||||||
*pp = NULL;
|
*pp = NULL;
|
||||||
@ -2791,8 +2791,11 @@ next_fenc(char_u **pp)
|
|||||||
r = p;
|
r = p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (r == NULL) /* out of memory */
|
if (r != NULL)
|
||||||
|
*alloced = TRUE;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
|
// out of memory
|
||||||
r = (char_u *)"";
|
r = (char_u *)"";
|
||||||
*pp = NULL;
|
*pp = NULL;
|
||||||
}
|
}
|
||||||
|
@ -769,6 +769,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1843,
|
||||||
/**/
|
/**/
|
||||||
1842,
|
1842,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user