aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Hillegeer <nicolas@hillegeer.com>2014-05-31 18:32:59 +0200
committerJustin M. Keyes <justinkz@gmail.com>2014-06-12 01:41:03 -0400
commit731761715a89d10b45c0a96340b55e071fe80b20 (patch)
tree45520c0b124d6850684d34e2353e9967187d8eee
parentf39fd5b4c424cc477a168fbf4eebfe315d23e614 (diff)
downloadrneovim-731761715a89d10b45c0a96340b55e071fe80b20.tar.gz
rneovim-731761715a89d10b45c0a96340b55e071fe80b20.tar.bz2
rneovim-731761715a89d10b45c0a96340b55e071fe80b20.zip
coverity/62617: fix leak in set_string_default
Also constified the arguments. The double casts for the `xstrdup` are ugly but `vim_strsave` doesn't take `const` arguments for now so I couldn't keep that.
-rw-r--r--src/nvim/option.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 37a5a61d43..6b820ea1ba 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -2216,21 +2216,20 @@ set_options_default (
win_comp_scroll(wp);
}
-/*
- * Set the Vi-default value of a string option.
- * Used for 'sh', 'backupskip' and 'term'.
- */
-void set_string_default(char *name, char_u *val)
+/// Set the Vi-default value of a string option.
+/// Used for 'sh', 'backupskip' and 'term'.
+///
+/// @param name The name of the option
+/// @param val The value of the option
+void set_string_default(const char *name, const char_u *val)
{
- char_u *p;
- int opt_idx;
-
- p = vim_strsave(val);
- opt_idx = findoption((char_u *)name);
+ int opt_idx = findoption((char_u *)name);
if (opt_idx >= 0) {
- if (options[opt_idx].flags & P_DEF_ALLOCED)
+ if (options[opt_idx].flags & P_DEF_ALLOCED) {
free(options[opt_idx].def_val[VI_DEFAULT]);
- options[opt_idx].def_val[VI_DEFAULT] = p;
+ }
+
+ options[opt_idx].def_val[VI_DEFAULT] = (char_u *) xstrdup((char *) val);
options[opt_idx].flags |= P_DEF_ALLOCED;
}
}