mirror of
https://github.com/neovim/neovim.git
synced 2025-10-08 19:06:31 +00:00
coverity/62615: fix leak in write_reg_contents_ex
Coverity detected a memory leak caused by not free'ing the value returned by get_expr_line_src (basically vim_strsave(expr_line)). Replaced the copying with direct manipulation of expr_line, since that also happens in other parts of the codebase. NOTE: I'm aware that this has different behaviour than vim_strnsave, namely vim_strnsave always allocates `len` bytes, even if the string is shorter. I don't see how that behaviour is helpful here though.
This commit is contained in:

committed by
Justin M. Keyes

parent
731761715a
commit
ebbd87b0be
@@ -375,14 +375,14 @@ void reset_search_dir(void)
|
||||
* Set the last search pattern. For ":let @/ =" and viminfo.
|
||||
* Also set the saved search pattern, so that this works in an autocommand.
|
||||
*/
|
||||
void set_last_search_pat(char_u *s, int idx, int magic, int setlast)
|
||||
void set_last_search_pat(const char_u *s, int idx, int magic, int setlast)
|
||||
{
|
||||
free(spats[idx].pat);
|
||||
/* An empty string means that nothing should be matched. */
|
||||
if (*s == NUL)
|
||||
spats[idx].pat = NULL;
|
||||
else
|
||||
spats[idx].pat = vim_strsave(s);
|
||||
spats[idx].pat = (char_u *) xstrdup((char *) s);
|
||||
spats[idx].magic = magic;
|
||||
spats[idx].no_scs = FALSE;
|
||||
spats[idx].off.dir = '/';
|
||||
|
Reference in New Issue
Block a user