summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Bostic <keith@wiredtiger.com>2013-11-15 20:24:14 -0500
committerKeith Bostic <keith@wiredtiger.com>2013-11-15 20:24:14 -0500
commit3fe3045cd13dad12afc16e71b542e755a806e41b (patch)
tree6e09f99130cd08dc55ef9b2cd8b7f2d3a94e3033
parentc355998f1b2ad3b652222d9b066ae7465c7633cf (diff)
downloadmongo-3fe3045cd13dad12afc16e71b542e755a806e41b.tar.gz
Cleanup up a set of allocations that were never checked for failure.
-rw-r--r--bench/wtperf/wtperf.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/bench/wtperf/wtperf.c b/bench/wtperf/wtperf.c
index 8be559717b3..a901404401f 100644
--- a/bench/wtperf/wtperf.c
+++ b/bench/wtperf/wtperf.c
@@ -120,7 +120,7 @@ typedef enum {
/* Forward function definitions. */
void *checkpoint_worker(void *);
-void config_assign(CONFIG *, const CONFIG *);
+int config_assign(CONFIG *, const CONFIG *);
void config_free(CONFIG *);
int config_opt(CONFIG *, WT_CONFIG_ITEM *, WT_CONFIG_ITEM *);
int config_opt_file(CONFIG *, WT_SESSION *, const char *);
@@ -133,7 +133,7 @@ int execute_workload(CONFIG *);
int find_table_count(CONFIG *);
void indent_lines(const char *, const char *);
void *insert_thread(void *);
-void lprintf(CONFIG *cfg, int err, uint32_t level, const char *fmt, ...)
+void lprintf(const CONFIG *cfg, int err, uint32_t level, const char *fmt, ...)
WT_GCC_ATTRIBUTE((format (printf, 4, 5)));
void *populate_thread(void *);
void print_config(CONFIG *);
@@ -269,7 +269,7 @@ sum_update_ops(CONFIG_THREAD *threads, u_int num)
}
static int
-enomem(CONFIG *cfg)
+enomem(const CONFIG *cfg)
{
const char *msg;
@@ -961,7 +961,8 @@ main(int argc, char *argv[])
/* Setup the default configuration values. */
memset(&cfg, 0, sizeof(cfg));
- config_assign(&cfg, &default_cfg);
+ if (config_assign(&cfg, &default_cfg))
+ goto err;
conn = NULL;
parse_session = NULL;
@@ -1232,7 +1233,7 @@ err: g_util_running = 0;
/* Assign the src config to the dest.
* Any storage allocated in dest is freed as a result.
*/
-void
+int
config_assign(CONFIG *dest, const CONFIG *src)
{
size_t i, len;
@@ -1245,14 +1246,16 @@ config_assign(CONFIG *dest, const CONFIG *src)
if (config_opts[i].type == STRING_TYPE ||
config_opts[i].type == CONFIG_STRING_TYPE) {
pstr = (char **)
- ((unsigned char *)dest + config_opts[i].offset);
+ ((u_char *)dest + config_opts[i].offset);
if (*pstr != NULL) {
len = strlen(*pstr) + 1;
- newstr = malloc(len);
+ if ((newstr = malloc(len)) == NULL)
+ return (enomem(src));
strncpy(newstr, *pstr, len);
*pstr = newstr;
}
}
+ return (0);
}
/* Free any storage allocated in the config struct.
@@ -1331,11 +1334,13 @@ config_opt(CONFIG *cfg, WT_CONFIG_ITEM *k, WT_CONFIG_ITEM *v)
strp = (char **)valueloc;
newlen = v->len + 1;
if (*strp == NULL) {
- newstr = calloc(newlen, sizeof(char));
+ if ((newstr = calloc(newlen, sizeof(char))) == NULL)
+ return (enomem(cfg));
strncpy(newstr, v->str, v->len);
} else {
newlen += (strlen(*strp) + 1);
- newstr = calloc(newlen, sizeof(char));
+ if ((newstr = calloc(newlen, sizeof(char))) == NULL)
+ return (enomem(cfg));
snprintf(newstr, newlen,
"%s,%*s", *strp, (int)v->len, v->str);
/* Free the old value now we've copied it. */
@@ -1351,7 +1356,8 @@ config_opt(CONFIG *cfg, WT_CONFIG_ITEM *k, WT_CONFIG_ITEM *v)
}
strp = (char **)valueloc;
free(*strp);
- newstr = malloc(v->len + 1);
+ if ((newstr = malloc(v->len + 1)) == NULL)
+ return (enomem(cfg));
strncpy(newstr, v->str, v->len);
newstr[v->len] = '\0';
*strp = newstr;
@@ -1497,7 +1503,9 @@ config_opt_str(CONFIG *cfg, WT_SESSION *parse_session,
int ret;
char *optstr;
- optstr = malloc(strlen(name) + strlen(value) + 4); /* name="value" */
+ /* name="value" */
+ if ((optstr = malloc(strlen(name) + strlen(value) + 4)) == NULL)
+ return (enomem(cfg));
sprintf(optstr, "%s=\"%s\"", name, value);
ret = config_opt_line(cfg, parse_session, optstr);
free(optstr);
@@ -1512,7 +1520,9 @@ config_opt_int(CONFIG *cfg, WT_SESSION *parse_session,
int ret;
char *optstr;
- optstr = malloc(strlen(name) + strlen(value) + 2); /* name=value */
+ /* name=value */
+ if ((optstr = malloc(strlen(name) + strlen(value) + 2)) == NULL)
+ return (enomem(cfg));
sprintf(optstr, "%s=%s", name, value);
ret = config_opt_line(cfg, parse_session, optstr);
free(optstr);
@@ -1607,7 +1617,7 @@ stop_threads(CONFIG *cfg, u_int num, CONFIG_THREAD **threadsp)
* Log printf - output a log message.
*/
void
-lprintf(CONFIG *cfg, int err, uint32_t level, const char *fmt, ...)
+lprintf(const CONFIG *cfg, int err, uint32_t level, const char *fmt, ...)
{
va_list ap;