The new implementation should be more friendly to static analyzers.
Coverity was getting confused into thinking that profile_iterator()
had the effect of returning a freed name pointer.
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25045
dc483132-0cff-0310-8789-
dd5450dbe970
set_results(const char *name, const char *value, char **ret_name,
char **ret_value)
{
- if (ret_name) {
- if (name) {
- *ret_name = strdup(name);
- if (!*ret_name)
- return ENOMEM;
- } else
- *ret_name = NULL;
+ char *name_copy = NULL, *value_copy = NULL;
+
+ if (ret_name && name) {
+ name_copy = strdup(name);
+ if (name_copy == NULL)
+ goto oom;
}
- if (ret_value) {
- if (value) {
- *ret_value = strdup(value);
- if (!*ret_value) {
- if (ret_name) {
- free(*ret_name);
- *ret_name = NULL;
- }
- return ENOMEM;
- }
- } else
- *ret_value = NULL;
+ if (ret_value && value) {
+ value_copy = strdup(value);
+ if (value_copy == NULL)
+ goto oom;
}
+ if (ret_name)
+ *ret_name = name_copy;
+ if (ret_value)
+ *ret_value = value_copy;
return 0;
+oom:
+ free(name_copy);
+ free(value_copy);
+ if (ret_name)
+ *ret_name = NULL;
+ if (ret_value)
+ *ret_value = NULL;
+ return ENOMEM;
}
errcode_t KRB5_CALLCONV