Only free the previously-set string value if we're actually going to
change it. This avoids the scenario where a caller does something
like:
char *str = strdup("defaultval");
/* ... */
cmd_OptionAsString(as, OPT_foo, &str);
resulting in 'str' pointing to freed memory when the relevant option
is not specified, or there is some other error.
Change-Id: If1f94d5eb39cc4dba9a4195ff20850ff81737eb9
Reviewed-on: http://gerrit.openafs.org/7475
Reviewed-by: Jeffrey Altman <jaltman@secure-endpoints.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
const char *str;
int code;
- if (*value)
- free(*value);
-
code = _get_config_string(syn, pos, &str);
if (code)
return code;
if (str == NULL)
return CMD_MISSING;
+ if (*value)
+ free(*value);
*value = strdup(str);
return 0;