From dcf8c15bfcc82475c36162d6fb0e9d829dd19dda Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Mon, 25 Jul 2011 15:54:33 +0000 Subject: [PATCH] Rewrite set_results() in prof_get.c 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 --- src/util/profile/prof_get.c | 41 ++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/util/profile/prof_get.c b/src/util/profile/prof_get.c index 844d22689..b2ea40ce1 100644 --- a/src/util/profile/prof_get.c +++ b/src/util/profile/prof_get.c @@ -544,28 +544,31 @@ static errcode_t 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 -- 2.26.2