mirror of
https://github.com/vim/vim.git
synced 2025-10-01 04:54:07 -04:00
patch 8.1.0642: swapinfo() leaks memory
Problem: swapinfo() leaks memory. Solution: Avoid allocating the strings twice.
This commit is contained in:
@@ -2055,21 +2055,16 @@ get_b0_dict(char_u *fname, dict_T *d)
|
||||
if (read_eintr(fd, &b0, sizeof(b0)) == sizeof(b0))
|
||||
{
|
||||
if (ml_check_b0_id(&b0) == FAIL)
|
||||
dict_add_string(d, "error",
|
||||
vim_strsave((char_u *)"Not a swap file"));
|
||||
dict_add_string(d, "error", (char_u *)"Not a swap file");
|
||||
else if (b0_magic_wrong(&b0))
|
||||
dict_add_string(d, "error",
|
||||
vim_strsave((char_u *)"Magic number mismatch"));
|
||||
dict_add_string(d, "error", (char_u *)"Magic number mismatch");
|
||||
else
|
||||
{
|
||||
/* we have swap information */
|
||||
dict_add_string(d, "version", vim_strnsave(b0.b0_version, 10));
|
||||
dict_add_string(d, "user",
|
||||
vim_strnsave(b0.b0_uname, B0_UNAME_SIZE));
|
||||
dict_add_string(d, "host",
|
||||
vim_strnsave(b0.b0_hname, B0_HNAME_SIZE));
|
||||
dict_add_string(d, "fname",
|
||||
vim_strnsave(b0.b0_fname, B0_FNAME_SIZE_ORG));
|
||||
dict_add_string_len(d, "version", b0.b0_version, 10);
|
||||
dict_add_string_len(d, "user", b0.b0_uname, B0_UNAME_SIZE);
|
||||
dict_add_string_len(d, "host", b0.b0_hname, B0_HNAME_SIZE);
|
||||
dict_add_string_len(d, "fname", b0.b0_fname, B0_FNAME_SIZE_ORG);
|
||||
|
||||
dict_add_number(d, "pid", char_to_long(b0.b0_pid));
|
||||
dict_add_number(d, "mtime", char_to_long(b0.b0_mtime));
|
||||
@@ -2080,12 +2075,11 @@ get_b0_dict(char_u *fname, dict_T *d)
|
||||
}
|
||||
}
|
||||
else
|
||||
dict_add_string(d, "error",
|
||||
vim_strsave((char_u *)"Cannot read file"));
|
||||
dict_add_string(d, "error", (char_u *)"Cannot read file");
|
||||
close(fd);
|
||||
}
|
||||
else
|
||||
dict_add_string(d, "error", vim_strsave((char_u *)"Cannot open file"));
|
||||
dict_add_string(d, "error", (char_u *)"Cannot open file");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user