aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/search.c
diff options
context:
space:
mode:
authorNicolas Hillegeer <nicolas@hillegeer.com>2014-05-31 19:07:38 +0200
committerJustin M. Keyes <justinkz@gmail.com>2014-06-12 01:41:03 -0400
commitebbd87b0be22405c82f2d1dc662241aa284f1622 (patch)
treedbf5c4ff03b9679a7ef4637cf413e8ce7f7ffcb3 /src/nvim/search.c
parent731761715a89d10b45c0a96340b55e071fe80b20 (diff)
downloadrneovim-ebbd87b0be22405c82f2d1dc662241aa284f1622.tar.gz
rneovim-ebbd87b0be22405c82f2d1dc662241aa284f1622.tar.bz2
rneovim-ebbd87b0be22405c82f2d1dc662241aa284f1622.zip
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.
Diffstat (limited to 'src/nvim/search.c')
-rw-r--r--src/nvim/search.c4
1 files changed, 2 insertions, 2 deletions
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 = '/';