vim-patch:8.1.0470: pointer ownership around fname_expand() is unclear

Problem:    Pointer ownership around fname_expand() is unclear.
Solution:   Allow b_ffname and b_sfname to point to the same allocated memory,
            only free one.  Update comments.
3d6014f033
This commit is contained in:
Jan Edmund Lazo
2020-12-19 21:58:33 -05:00
parent e465157ecd
commit 7390cc8b29
4 changed files with 67 additions and 41 deletions

View File

@@ -4217,7 +4217,9 @@ void shorten_buf_fname(buf_T *buf, char_u *dirname, int force)
&& (force
|| buf->b_sfname == NULL
|| path_is_absolute(buf->b_sfname))) {
XFREE_CLEAR(buf->b_sfname);
if (buf->b_sfname != buf->b_ffname) {
XFREE_CLEAR(buf->b_sfname);
}
p = path_shorten_fname(buf->b_ffname, dirname);
if (p != NULL) {
buf->b_sfname = vim_strsave(p);