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.
This commit is contained in:
Nicolas Hillegeer
2014-05-31 18:32:59 +02:00
committed by Justin M. Keyes
parent f39fd5b4c4
commit 731761715a

View File

@@ -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;
}
}