summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Bostic <keith.bostic@mongodb.com>2017-03-27 09:18:34 -0400
committersueloverso <sue@mongodb.com>2017-03-27 09:18:34 -0400
commite36d8cdb2748ad5b6713b824bbe7be0c8f11c14d (patch)
tree912dd02692bf5fc5b19a64a3a4d584900be5e43f
parentc2bde1ea5a810f47f26fb7a6e70fe9612ea15f1f (diff)
downloadmongo-e36d8cdb2748ad5b6713b824bbe7be0c8f11c14d.tar.gz
WT-3240 Coverity reports (#3354)
* WT-3240 Coverity reports Coverity report 1373075: allocated memory is leaked if __wt_snprintf fails. * Coverity report 1373074: allocated memory is leaked if __wt_snprintf fails. * Coverity report 1373073: allocated memory is leaked if __wt_snprintf fails. * Coverity report 1373072: allocated memory is leaked if __wt_snprintf fails. * Coverity report 1373071: allocated memory is leaked if __wt_snprintf fails. * Coverity report 1369053: CID 1369053 (#1 of 1): Unused value (UNUSED_VALUE) assigned_pointer: Assigning value from "," to append_comma here, but that stored value is overwritten before it can be used.
-rw-r--r--bench/wtperf/wtperf.c2
-rw-r--r--src/config/config_api.c2
-rw-r--r--src/os_common/filename.c18
-rw-r--r--src/utilities/util_dump.c4
-rw-r--r--src/utilities/util_load_json.c8
-rw-r--r--src/utilities/util_main.c12
6 files changed, 25 insertions, 21 deletions
diff --git a/bench/wtperf/wtperf.c b/bench/wtperf/wtperf.c
index bdc0b0f3b3c..6d79eebe8b2 100644
--- a/bench/wtperf/wtperf.c
+++ b/bench/wtperf/wtperf.c
@@ -2623,7 +2623,6 @@ main(int argc, char *argv[])
testutil_check(__wt_snprintf_len_incr(
cc_buf + pos, req_len - pos, &pos, "%s%s",
append_comma, user_cconfig));
- append_comma = ",";
}
if (strlen(cc_buf) != 0 && (ret =
@@ -2658,7 +2657,6 @@ main(int argc, char *argv[])
testutil_check(__wt_snprintf_len_incr(
tc_buf + pos, req_len - pos, &pos, "%s%s",
append_comma, user_tconfig));
- append_comma = ",";
}
if (strlen(tc_buf) != 0 && (ret =
diff --git a/src/config/config_api.c b/src/config/config_api.c
index 88e173459f9..c1299baaafe 100644
--- a/src/config/config_api.c
+++ b/src/config/config_api.c
@@ -278,8 +278,8 @@ __wt_configure_method(WT_SESSION_IMPL *session,
entry->method = (*epp)->method;
len = strlen((*epp)->base) + strlen(",") + strlen(config) + 1;
WT_ERR(__wt_calloc_def(session, len, &p));
- WT_ERR(__wt_snprintf(p, len, "%s,%s", (*epp)->base, config));
entry->base = p;
+ WT_ERR(__wt_snprintf(p, len, "%s,%s", (*epp)->base, config));
/*
* There may be a default value in the config argument passed in (for
diff --git a/src/os_common/filename.c b/src/os_common/filename.c
index f803144a3fb..d5695f63d91 100644
--- a/src/os_common/filename.c
+++ b/src/os_common/filename.c
@@ -29,6 +29,7 @@ int
__wt_nfilename(
WT_SESSION_IMPL *session, const char *name, size_t namelen, char **path)
{
+ WT_DECL_RET;
size_t len;
char *buf;
@@ -39,16 +40,17 @@ __wt_nfilename(
* the exists API which is used by the test utilities.
*/
if (session == NULL || __wt_absolute_path(name))
- WT_RET(__wt_strndup(session, name, namelen, path));
- else {
- len = strlen(S2C(session)->home) + 1 + namelen + 1;
- WT_RET(__wt_calloc(session, 1, len, &buf));
- WT_RET(__wt_snprintf(buf, len, "%s%s%.*s", S2C(session)->home,
- __wt_path_separator(), (int)namelen, name));
- *path = buf;
- }
+ return (__wt_strndup(session, name, namelen, path));
+ len = strlen(S2C(session)->home) + 1 + namelen + 1;
+ WT_RET(__wt_calloc(session, 1, len, &buf));
+ WT_ERR(__wt_snprintf(buf, len, "%s%s%.*s",
+ S2C(session)->home, __wt_path_separator(), (int)namelen, name));
+ *path = buf;
return (0);
+
+err: __wt_free(session, buf);
+ return (ret);
}
/*
diff --git a/src/utilities/util_dump.c b/src/utilities/util_dump.c
index 238e2757099..955148b7d46 100644
--- a/src/utilities/util_dump.c
+++ b/src/utilities/util_dump.c
@@ -437,8 +437,10 @@ dump_table_parts_config(WT_SESSION *session, WT_CURSOR *cursor,
len = strlen(entry) + strlen(name) + 1;
if ((uriprefix = malloc(len)) == NULL)
return (util_err(session, errno, NULL));
- if ((ret = __wt_snprintf(uriprefix, len, "%s%s", entry, name)) != 0)
+ if ((ret = __wt_snprintf(uriprefix, len, "%s%s", entry, name)) != 0) {
+ free(uriprefix);
return (util_err(session, ret, NULL));
+ }
/*
* Search the file looking for column group and index key/value pairs:
diff --git a/src/utilities/util_load_json.c b/src/utilities/util_load_json.c
index af5c2576b26..c693e2b7651 100644
--- a/src/utilities/util_load_json.c
+++ b/src/utilities/util_load_json.c
@@ -153,13 +153,15 @@ json_kvraw_append(WT_SESSION *session,
needsize = strlen(ins->kvraw) + len + 2;
if ((tmp = malloc(needsize)) == NULL)
return (util_err(session, errno, NULL));
- if ((ret = __wt_snprintf(
- tmp, needsize, "%s %.*s", ins->kvraw, (int)len, str)) != 0)
- return (util_err(session, ret, NULL));
+ WT_ERR(__wt_snprintf(
+ tmp, needsize, "%s %.*s", ins->kvraw, (int)len, str));
free(ins->kvraw);
ins->kvraw = tmp;
}
return (0);
+
+err: free(tmp);
+ return (util_err(session, ret, NULL));
}
/*
diff --git a/src/utilities/util_main.c b/src/utilities/util_main.c
index 2b4ef36081a..c6f225bb667 100644
--- a/src/utilities/util_main.c
+++ b/src/utilities/util_main.c
@@ -326,12 +326,12 @@ util_uri(WT_SESSION *session, const char *s, const char *type)
* the default type for the operation.
*/
if (strchr(s, ':') != NULL)
- ret = __wt_snprintf(name, len, "%s", s);
+ WT_ERR(__wt_snprintf(name, len, "%s", s));
else
- ret = __wt_snprintf(name, len, "%s:%s", type, s);
- if (ret != 0) {
- (void)util_err(session, ret, NULL);
- return (NULL);
- }
+ WT_ERR(__wt_snprintf(name, len, "%s:%s", type, s));
return (name);
+
+err: free(name);
+ (void)util_err(session, ret, NULL);
+ return (NULL);
}