From ebbd87b0be22405c82f2d1dc662241aa284f1622 Mon Sep 17 00:00:00 2001 From: Nicolas Hillegeer Date: Sat, 31 May 2014 19:07:38 +0200 Subject: 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. --- src/nvim/search.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/search.c') diff --git a/src/nvim/search.c b/src/nvim/search.c index 5ba30eeb00..08fdfa4b63 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -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 = '/'; -- cgit