aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-01-11 13:44:10 -0500
committerNick Mathewson <nickm@torproject.org>2012-01-16 15:02:51 -0500
commitedcc9981d8b8894d2ef4e0d617a20d7d99547817 (patch)
tree44476ecc42282d66930fb659d27fc9ad3c5a74b6 /src/or
parent9c6d913b9e1b84ffcefb2cbd9cfe6f7bd15fc9b3 (diff)
downloadtor-edcc9981d8b8894d2ef4e0d617a20d7d99547817.tar
tor-edcc9981d8b8894d2ef4e0d617a20d7d99547817.tar.gz
Try to use smartlist_add_asprintf consistently
(To ensure correctness, in every case, make sure that the temporary variable is deleted, renamed, or lowered in scope, so we can't have any bugs related to accidentally relying on the no-longer-filled variable.)
Diffstat (limited to 'src/or')
-rw-r--r--src/or/circuitbuild.c10
-rw-r--r--src/or/config.c12
-rw-r--r--src/or/control.c47
-rw-r--r--src/or/directory.c23
-rw-r--r--src/or/dirvote.c42
-rw-r--r--src/or/geoip.c10
-rw-r--r--src/or/networkstatus.c27
-rw-r--r--src/or/rephist.c65
-rw-r--r--src/or/router.c4
-rw-r--r--src/or/transports.c9
10 files changed, 89 insertions, 160 deletions
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index a9e5d2294..216c92658 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -1545,15 +1545,13 @@ circuit_list_path_impl(origin_circuit_t *circ, int verbose, int verbose_names)
if (verbose) {
const char *nickname = build_state_get_exit_nickname(circ->build_state);
- char *cp;
- tor_asprintf(&cp, "%s%s circ (length %d%s%s):",
+ smartlist_add_asprintf(elements, "%s%s circ (length %d%s%s):",
circ->build_state->is_internal ? "internal" : "exit",
circ->build_state->need_uptime ? " (high-uptime)" : "",
circ->build_state->desired_path_len,
circ->_base.state == CIRCUIT_STATE_OPEN ? "" : ", last hop ",
circ->_base.state == CIRCUIT_STATE_OPEN ? "" :
(nickname?nickname:"*unnamed*"));
- smartlist_add(elements, cp);
}
hop = circ->cpath;
@@ -3599,19 +3597,17 @@ log_entry_guards(int severity)
SMARTLIST_FOREACH_BEGIN(entry_guards, entry_guard_t *, e)
{
const char *msg = NULL;
- char *cp;
if (entry_is_live(e, 0, 1, 0, &msg))
- tor_asprintf(&cp, "%s [%s] (up %s)",
+ smartlist_add_asprintf(elements, "%s [%s] (up %s)",
e->nickname,
hex_str(e->identity, DIGEST_LEN),
e->made_contact ? "made-contact" : "never-contacted");
else
- tor_asprintf(&cp, "%s [%s] (%s, %s)",
+ smartlist_add_asprintf(elements, "%s [%s] (%s, %s)",
e->nickname,
hex_str(e->identity, DIGEST_LEN),
msg,
e->made_contact ? "made-contact" : "never-contacted");
- smartlist_add(elements, cp);
}
SMARTLIST_FOREACH_END(e);
diff --git a/src/or/config.c b/src/or/config.c
index 341bc15d2..d4a4e0349 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -3147,11 +3147,9 @@ config_dump(const config_format_t *fmt, const void *default_options,
line = assigned = get_assigned_option(fmt, options, fmt->vars[i].name, 1);
for (; line; line = line->next) {
- char *tmp;
- tor_asprintf(&tmp, "%s%s %s\n",
+ smartlist_add_asprintf(elements, "%s%s %s\n",
comment_option ? "# " : "",
line->key, line->value);
- smartlist_add(elements, tmp);
}
config_free_lines(assigned);
}
@@ -3159,9 +3157,7 @@ config_dump(const config_format_t *fmt, const void *default_options,
if (fmt->extra) {
line = *(config_line_t**)STRUCT_VAR_P(options, fmt->extra->var_offset);
for (; line; line = line->next) {
- char *tmp;
- tor_asprintf(&tmp, "%s %s\n", line->key, line->value);
- smartlist_add(elements, tmp);
+ smartlist_add_asprintf(elements, "%s %s\n", line->key, line->value);
}
}
@@ -6994,7 +6990,6 @@ getinfo_helper_config(control_connection_t *conn,
for (i = 0; _option_vars[i].name; ++i) {
const config_var_t *var = &_option_vars[i];
const char *type;
- char *line;
switch (var->type) {
case CONFIG_TYPE_STRING: type = "String"; break;
case CONFIG_TYPE_FILENAME: type = "Filename"; break;
@@ -7018,8 +7013,7 @@ getinfo_helper_config(control_connection_t *conn,
}
if (!type)
continue;
- tor_asprintf(&line, "%s %s\n",var->name,type);
- smartlist_add(sl, line);
+ smartlist_add_asprintf(sl, "%s %s\n",var->name,type);
}
*answer = smartlist_join_strings(sl, "", 0, NULL);
SMARTLIST_FOREACH(sl, char *, c, tor_free(c));
diff --git a/src/or/control.c b/src/or/control.c
index a6b8e4fa9..7bb11cd8c 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -525,18 +525,15 @@ control_ports_write_to_file(void)
lines = smartlist_create();
SMARTLIST_FOREACH_BEGIN(get_connection_array(), const connection_t *, conn) {
- char *port_str = NULL;
if (conn->type != CONN_TYPE_CONTROL_LISTENER || conn->marked_for_close)
continue;
#ifdef AF_UNIX
if (conn->socket_family == AF_UNIX) {
- tor_asprintf(&port_str, "UNIX_PORT=%s\n", conn->address);
- smartlist_add(lines, port_str);
+ smartlist_add_asprintf(lines, "UNIX_PORT=%s\n", conn->address);
continue;
}
#endif
- tor_asprintf(&port_str, "PORT=%s:%d\n", conn->address, conn->port);
- smartlist_add(lines, port_str);
+ smartlist_add_asprintf(lines, "PORT=%s:%d\n", conn->address, conn->port);
} SMARTLIST_FOREACH_END(conn);
joined = smartlist_join_strings(lines, "", 0, NULL);
@@ -1558,7 +1555,6 @@ getinfo_helper_listeners(control_connection_t *control_conn,
res = smartlist_create();
SMARTLIST_FOREACH_BEGIN(get_connection_array(), connection_t *, conn) {
- char *addr;
struct sockaddr_storage ss;
socklen_t ss_len = sizeof(ss);
@@ -1566,14 +1562,13 @@ getinfo_helper_listeners(control_connection_t *control_conn,
continue;
if (getsockname(conn->s, (struct sockaddr *)&ss, &ss_len) < 0) {
- tor_asprintf(&addr, "%s:%d", conn->address, (int)conn->port);
+ smartlist_add_asprintf(res, "%s:%d", conn->address, (int)conn->port);
} else {
char *tmp = tor_sockaddr_to_str((struct sockaddr *)&ss);
- addr = esc_for_log(tmp);
+ smartlist_add(res, esc_for_log(tmp));
tor_free(tmp);
}
- if (addr)
- smartlist_add(res, addr);
+
} SMARTLIST_FOREACH_END(conn);
*answer = smartlist_join_strings(res, " ", 0, NULL);
@@ -1798,7 +1793,6 @@ circuit_describe_status_for_controller(origin_circuit_t *circ)
}
{
- char *buildflags = NULL;
cpath_build_state_t *build_state = circ->build_state;
smartlist_t *flaglist = smartlist_create();
char *flaglist_joined;
@@ -1816,8 +1810,7 @@ circuit_describe_status_for_controller(origin_circuit_t *circ)
if (smartlist_len(flaglist)) {
flaglist_joined = smartlist_join_strings(flaglist, ",", 0, NULL);
- tor_asprintf(&buildflags, "BUILD_FLAGS=%s", flaglist_joined);
- smartlist_add(descparts, buildflags);
+ smartlist_add_asprintf(descparts, "BUILD_FLAGS=%s", flaglist_joined);
tor_free(flaglist_joined);
}
@@ -1825,43 +1818,29 @@ circuit_describe_status_for_controller(origin_circuit_t *circ)
smartlist_free(flaglist);
}
- {
- char *purpose = NULL;
- tor_asprintf(&purpose, "PURPOSE=%s",
- circuit_purpose_to_controller_string(circ->_base.purpose));
- smartlist_add(descparts, purpose);
- }
+ smartlist_add_asprintf(descparts, "PURPOSE=%s",
+ circuit_purpose_to_controller_string(circ->_base.purpose));
{
- char *hs_state_arg = NULL;
const char *hs_state =
circuit_purpose_to_controller_hs_state_string(circ->_base.purpose);
if (hs_state != NULL) {
- tor_asprintf(&hs_state_arg, "HS_STATE=%s",
- hs_state);
-
- smartlist_add(descparts, hs_state_arg);
+ smartlist_add_asprintf(descparts, "HS_STATE=%s", hs_state);
}
}
if (circ->rend_data != NULL) {
- char *rend_query_arg = NULL;
-
- tor_asprintf(&rend_query_arg, "REND_QUERY=%s",
+ smartlist_add_asprintf(descparts, "REND_QUERY=%s",
circ->rend_data->onion_address);
- smartlist_add(descparts, rend_query_arg);
}
{
- char *time_created_arg = NULL;
char tbuf[ISO_TIME_USEC_LEN+1];
format_iso_time_nospace_usec(tbuf, &circ->_base.timestamp_created);
- tor_asprintf(&time_created_arg, "TIME_CREATED=%s", tbuf);
-
- smartlist_add(descparts, time_created_arg);
+ smartlist_add_asprintf(descparts, "TIME_CREATED=%s", tbuf);
}
rv = smartlist_join_strings(descparts, " ", 0, NULL);
@@ -2218,18 +2197,16 @@ static char *
list_getinfo_options(void)
{
int i;
- char *buf=NULL;
smartlist_t *lines = smartlist_create();
char *ans;
for (i = 0; getinfo_items[i].varname; ++i) {
if (!getinfo_items[i].desc)
continue;
- tor_asprintf(&buf, "%s%s -- %s\n",
+ smartlist_add_asprintf(lines, "%s%s -- %s\n",
getinfo_items[i].varname,
getinfo_items[i].is_prefix ? "*" : "",
getinfo_items[i].desc);
- smartlist_add(lines, buf);
}
smartlist_sort_strings(lines);
diff --git a/src/or/directory.c b/src/or/directory.c
index 12636bac3..8087d7603 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -1124,7 +1124,6 @@ directory_send_command(dir_connection_t *conn,
smartlist_t *headers = smartlist_create();
char *url;
char request[8192];
- char *header;
const char *httpcommand = NULL;
size_t len;
@@ -1147,8 +1146,7 @@ directory_send_command(dir_connection_t *conn,
if (if_modified_since) {
char b[RFC1123_TIME_LEN+1];
format_rfc1123_time(b, if_modified_since);
- tor_asprintf(&header, "If-Modified-Since: %s\r\n", b);
- smartlist_add(headers, header);
+ smartlist_add_asprintf(headers, "If-Modified-Since: %s\r\n", b);
}
/* come up with some proxy lines, if we're using one. */
@@ -1163,11 +1161,10 @@ directory_send_command(dir_connection_t *conn,
log_warn(LD_BUG, "Encoding http authenticator failed");
}
if (base64_authenticator) {
- tor_asprintf(&header,
+ smartlist_add_asprintf(headers,
"Proxy-Authorization: Basic %s\r\n",
base64_authenticator);
tor_free(base64_authenticator);
- smartlist_add(headers, header);
}
} else {
proxystring[0] = 0;
@@ -1238,8 +1235,7 @@ directory_send_command(dir_connection_t *conn,
httpcommand = "POST";
url = tor_strdup("/tor/");
if (why) {
- tor_asprintf(&header, "X-Desc-Gen-Reason: %s\r\n", why);
- smartlist_add(headers, header);
+ smartlist_add_asprintf(headers, "X-Desc-Gen-Reason: %s\r\n", why);
}
break;
}
@@ -1294,15 +1290,16 @@ directory_send_command(dir_connection_t *conn,
tor_free(url);
if (!strcmp(httpcommand, "POST") || payload) {
- tor_asprintf(&header, "Content-Length: %lu\r\n",
+ smartlist_add_asprintf(headers, "Content-Length: %lu\r\n",
payload ? (unsigned long)payload_len : 0);
- smartlist_add(headers, header);
}
- header = smartlist_join_strings(headers, "", 0, NULL);
- tor_snprintf(request, sizeof(request), " HTTP/1.0\r\nHost: %s\r\n%s\r\n",
- hoststring, header);
- tor_free(header);
+ {
+ char *header = smartlist_join_strings(headers, "", 0, NULL);
+ tor_snprintf(request, sizeof(request), " HTTP/1.0\r\nHost: %s\r\n%s\r\n",
+ hoststring, header);
+ tor_free(header);
+ }
connection_write_to_buf(request, strlen(request), TO_CONN(conn));
diff --git a/src/or/dirvote.c b/src/or/dirvote.c
index 3bb165aee..72f49c7f4 100644
--- a/src/or/dirvote.c
+++ b/src/or/dirvote.c
@@ -1475,7 +1475,6 @@ networkstatus_compute_consensus(smartlist_t *votes,
chunks = smartlist_create();
{
- char *buf=NULL;
char va_buf[ISO_TIME_LEN+1], fu_buf[ISO_TIME_LEN+1],
vu_buf[ISO_TIME_LEN+1];
char *flaglist;
@@ -1484,20 +1483,17 @@ networkstatus_compute_consensus(smartlist_t *votes,
format_iso_time(vu_buf, valid_until);
flaglist = smartlist_join_strings(flags, " ", 0, NULL);
- tor_asprintf(&buf, "network-status-version 3%s%s\n"
+ smartlist_add_asprintf(chunks, "network-status-version 3%s%s\n"
"vote-status consensus\n",
flavor == FLAV_NS ? "" : " ",
flavor == FLAV_NS ? "" : flavor_name);
- smartlist_add(chunks, buf);
-
if (consensus_method >= 2) {
- tor_asprintf(&buf, "consensus-method %d\n",
+ smartlist_add_asprintf(chunks, "consensus-method %d\n",
consensus_method);
- smartlist_add(chunks, buf);
}
- tor_asprintf(&buf,
+ smartlist_add_asprintf(chunks,
"valid-after %s\n"
"fresh-until %s\n"
"valid-until %s\n"
@@ -1508,7 +1504,6 @@ networkstatus_compute_consensus(smartlist_t *votes,
va_buf, fu_buf, vu_buf,
vote_seconds, dist_seconds,
client_versions, server_versions, flaglist);
- smartlist_add(chunks, buf);
tor_free(flaglist);
}
@@ -1550,7 +1545,6 @@ networkstatus_compute_consensus(smartlist_t *votes,
char votedigest[HEX_DIGEST_LEN+1];
networkstatus_t *v = e->v;
networkstatus_voter_info_t *voter = get_voter(v);
- char *buf = NULL;
if (e->is_legacy)
tor_assert(consensus_method >= 2);
@@ -1559,20 +1553,18 @@ networkstatus_compute_consensus(smartlist_t *votes,
base16_encode(votedigest, sizeof(votedigest), voter->vote_digest,
DIGEST_LEN);
- tor_asprintf(&buf,
+ smartlist_add_asprintf(chunks,
"dir-source %s%s %s %s %s %d %d\n",
voter->nickname, e->is_legacy ? "-legacy" : "",
fingerprint, voter->address, fmt_addr32(voter->addr),
voter->dir_port,
voter->or_port);
- smartlist_add(chunks, buf);
if (! e->is_legacy) {
- tor_asprintf(&buf,
+ smartlist_add_asprintf(chunks,
"contact %s\n"
"vote-digest %s\n",
voter->contact,
votedigest);
- smartlist_add(chunks, buf);
}
} SMARTLIST_FOREACH_END(e);
SMARTLIST_FOREACH(dir_sources, dir_src_ent_t *, e, tor_free(e));
@@ -1709,7 +1701,6 @@ networkstatus_compute_consensus(smartlist_t *votes,
int naming_conflict = 0;
int n_listing = 0;
int i;
- char *buf=NULL;
char microdesc_digest[DIGEST256_LEN];
/* Of the next-to-be-considered digest in each voter, which is first? */
@@ -1977,10 +1968,9 @@ networkstatus_compute_consensus(smartlist_t *votes,
/* Now an m line, if applicable. */
if (flavor == FLAV_MICRODESC &&
!tor_digest256_is_zero(microdesc_digest)) {
- char m[BASE64_DIGEST256_LEN+1], *cp;
+ char m[BASE64_DIGEST256_LEN+1];
digest256_to_base64(m, microdesc_digest);
- tor_asprintf(&cp, "m %s\n", m);
- smartlist_add(chunks, cp);
+ smartlist_add_asprintf(chunks, "m %s\n", m);
}
/* Next line is all flags. The "\n" is missing. */
smartlist_add(chunks,
@@ -1993,15 +1983,12 @@ networkstatus_compute_consensus(smartlist_t *votes,
smartlist_add(chunks, tor_strdup("\n"));
/* Now the weight line. */
if (rs_out.has_bandwidth) {
- char *cp=NULL;
- tor_asprintf(&cp, "w Bandwidth=%d\n", rs_out.bandwidth);
- smartlist_add(chunks, cp);
+ smartlist_add_asprintf(chunks, "w Bandwidth=%d\n", rs_out.bandwidth);
}
/* Now the exitpolicy summary line. */
if (rs_out.has_exitsummary && flavor == FLAV_NS) {
- tor_asprintf(&buf, "p %s\n", rs_out.exitsummary);
- smartlist_add(chunks, buf);
+ smartlist_add_asprintf(chunks, "p %s\n", rs_out.exitsummary);
}
/* And the loop is over and we move on to the next router */
@@ -2083,7 +2070,6 @@ networkstatus_compute_consensus(smartlist_t *votes,
size_t digest_len =
flavor == FLAV_NS ? DIGEST_LEN : DIGEST256_LEN;
const char *algname = crypto_digest_algorithm_get_name(digest_alg);
- char *buf = NULL;
char sigbuf[4096];
smartlist_add(chunks, tor_strdup("directory-signature "));
@@ -2097,14 +2083,13 @@ networkstatus_compute_consensus(smartlist_t *votes,
/* add the junk that will go at the end of the line. */
if (flavor == FLAV_NS) {
- tor_asprintf(&buf, "%s %s\n", fingerprint,
+ smartlist_add_asprintf(chunks, "%s %s\n", fingerprint,
signing_key_fingerprint);
} else {
- tor_asprintf(&buf, "%s %s %s\n",
+ smartlist_add_asprintf(chunks, "%s %s %s\n",
algname, fingerprint,
signing_key_fingerprint);
}
- smartlist_add(chunks, buf);
/* And the signature. */
sigbuf[0] = '\0';
if (router_append_dirobj_signature(sigbuf, sizeof(sigbuf),
@@ -2122,14 +2107,13 @@ networkstatus_compute_consensus(smartlist_t *votes,
crypto_pk_get_fingerprint(legacy_signing_key,
signing_key_fingerprint, 0);
if (flavor == FLAV_NS) {
- tor_asprintf(&buf, "%s %s\n", fingerprint,
+ smartlist_add_asprintf(chunks, "%s %s\n", fingerprint,
signing_key_fingerprint);
} else {
- tor_asprintf(&buf, "%s %s %s\n",
+ smartlist_add_asprintf(chunks, "%s %s %s\n",
algname, fingerprint,
signing_key_fingerprint);
}
- smartlist_add(chunks, buf);
sigbuf[0] = '\0';
if (router_append_dirobj_signature(sigbuf, sizeof(sigbuf),
digest, digest_len,
diff --git a/src/or/geoip.c b/src/or/geoip.c
index 73194ae9c..3e1ee5987 100644
--- a/src/or/geoip.c
+++ b/src/or/geoip.c
@@ -856,9 +856,7 @@ geoip_get_client_history(geoip_client_action_t action)
/* Build the result. */
chunks = smartlist_create();
SMARTLIST_FOREACH(entries, c_hist_t *, ch, {
- char *buf=NULL;
- tor_asprintf(&buf, "%s=%u", ch->country, ch->total);
- smartlist_add(chunks, buf);
+ smartlist_add_asprintf(chunks, "%s=%u", ch->country, ch->total);
});
result = smartlist_join_strings(chunks, ",", 0, NULL);
done:
@@ -907,10 +905,8 @@ geoip_get_request_history(geoip_client_action_t action)
strings = smartlist_create();
SMARTLIST_FOREACH(entries, c_hist_t *, ent, {
- char *buf = NULL;
- tor_asprintf(&buf, "%s=%u", ent->country, ent->total);
- smartlist_add(strings, buf);
- });
+ smartlist_add_asprintf(strings, "%s=%u", ent->country, ent->total);
+ });
result = smartlist_join_strings(strings, ",", 0, NULL);
SMARTLIST_FOREACH(strings, char *, cp, tor_free(cp));
SMARTLIST_FOREACH(entries, c_hist_t *, ent, tor_free(ent));
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
index a835e78b8..0a1fc08bf 100644
--- a/src/or/networkstatus.c
+++ b/src/or/networkstatus.c
@@ -598,39 +598,38 @@ networkstatus_check_consensus_signature(networkstatus_t *consensus,
hex_str(ds->v3_identity_digest, DIGEST_LEN));
});
{
+ char *joined;
smartlist_t *sl = smartlist_create();
- char *cp;
char *tmp = smartlist_join_strings(list_good, " ", 0, NULL);
- tor_asprintf(&cp, "A consensus needs %d good signatures from recognized "
+ smartlist_add_asprintf(sl,
+ "A consensus needs %d good signatures from recognized "
"authorities for us to accept it. This one has %d (%s).",
n_required, n_good, tmp);
tor_free(tmp);
- smartlist_add(sl,cp);
if (n_no_signature) {
tmp = smartlist_join_strings(list_no_signature, " ", 0, NULL);
- tor_asprintf(&cp, "%d (%s) of the authorities we know didn't sign it.",
+ smartlist_add_asprintf(sl,
+ "%d (%s) of the authorities we know didn't sign it.",
n_no_signature, tmp);
tor_free(tmp);
- smartlist_add(sl,cp);
}
if (n_unknown) {
- tor_asprintf(&cp, "It has %d signatures from authorities we don't "
+ smartlist_add_asprintf(sl,
+ "It has %d signatures from authorities we don't "
"recognize.", n_unknown);
- smartlist_add(sl,cp);
}
if (n_bad) {
- tor_asprintf(&cp, "%d of the signatures on it didn't verify "
+ smartlist_add_asprintf(sl, "%d of the signatures on it didn't verify "
"correctly.", n_bad);
- smartlist_add(sl,cp);
}
if (n_missing_key) {
- tor_asprintf(&cp, "We were unable to check %d of the signatures, "
+ smartlist_add_asprintf(sl,
+ "We were unable to check %d of the signatures, "
"because we were missing the keys.", n_missing_key);
- smartlist_add(sl,cp);
}
- cp = smartlist_join_strings(sl, " ", 0, NULL);
- log(severity, LD_DIR, "%s", cp);
- tor_free(cp);
+ joined = smartlist_join_strings(sl, " ", 0, NULL);
+ log(severity, LD_DIR, "%s", joined);
+ tor_free(joined);
SMARTLIST_FOREACH(sl, char *, c, tor_free(c));
smartlist_free(sl);
}
diff --git a/src/or/rephist.c b/src/or/rephist.c
index 6bbb93b82..b7bd2387f 100644
--- a/src/or/rephist.c
+++ b/src/or/rephist.c
@@ -1588,7 +1588,6 @@ rep_hist_update_bwhist_state_section(or_state_t *state,
time_t *s_begins,
int *s_interval)
{
- char *cp;
int i,j;
uint64_t maxval;
@@ -1626,17 +1625,17 @@ rep_hist_update_bwhist_state_section(or_state_t *state,
for (j=0; j < b->num_maxes_set; ++j,++i) {
if (i >= NUM_TOTALS)
i = 0;
- tor_asprintf(&cp, U64_FORMAT, U64_PRINTF_ARG(b->totals[i] & ~0x3ff));
- smartlist_add(*s_values, cp);
+ smartlist_add_asprintf(*s_values, U64_FORMAT,
+ U64_PRINTF_ARG(b->totals[i] & ~0x3ff));
maxval = b->maxima[i] / NUM_SECS_ROLLING_MEASURE;
- tor_asprintf(&cp, U64_FORMAT, U64_PRINTF_ARG(maxval & ~0x3ff));
- smartlist_add(*s_maxima, cp);
+ smartlist_add_asprintf(*s_maxima, U64_FORMAT,
+ U64_PRINTF_ARG(maxval & ~0x3ff));
}
- tor_asprintf(&cp, U64_FORMAT, U64_PRINTF_ARG(b->total_in_period & ~0x3ff));
- smartlist_add(*s_values, cp);
+ smartlist_add_asprintf(*s_values, U64_FORMAT,
+ U64_PRINTF_ARG(b->total_in_period & ~0x3ff));
maxval = b->max_total / NUM_SECS_ROLLING_MEASURE;
- tor_asprintf(&cp, U64_FORMAT, U64_PRINTF_ARG(maxval & ~0x3ff));
- smartlist_add(*s_maxima, cp);
+ smartlist_add_asprintf(*s_maxima, U64_FORMAT,
+ U64_PRINTF_ARG(maxval & ~0x3ff));
}
/** Update <b>state</b> with the newest bandwidth history. Done before
@@ -2125,7 +2124,6 @@ rep_hist_format_exit_stats(time_t now)
uint64_t cur_bytes = 0, other_read = 0, other_written = 0,
total_read = 0, total_written = 0;
uint32_t total_streams = 0, other_streams = 0;
- char *buf;
smartlist_t *written_strings, *read_strings, *streams_strings;
char *written_string, *read_string, *streams_string;
char t[ISO_TIME_LEN+1];
@@ -2204,9 +2202,8 @@ rep_hist_format_exit_stats(time_t now)
exit_bytes_written[cur_port],
EXIT_STATS_ROUND_UP_BYTES);
num /= 1024;
- buf = NULL;
- tor_asprintf(&buf, "%d="U64_FORMAT, cur_port, U64_PRINTF_ARG(num));
- smartlist_add(written_strings, buf);
+ smartlist_add_asprintf(written_strings, "%d="U64_FORMAT,
+ cur_port, U64_PRINTF_ARG(num));
other_written -= exit_bytes_written[cur_port];
}
if (exit_bytes_read[cur_port] > 0) {
@@ -2214,18 +2211,15 @@ rep_hist_format_exit_stats(time_t now)
exit_bytes_read[cur_port],
EXIT_STATS_ROUND_UP_BYTES);
num /= 1024;
- buf = NULL;
- tor_asprintf(&buf, "%d="U64_FORMAT, cur_port, U64_PRINTF_ARG(num));
- smartlist_add(read_strings, buf);
+ smartlist_add_asprintf(read_strings, "%d="U64_FORMAT,
+ cur_port, U64_PRINTF_ARG(num));
other_read -= exit_bytes_read[cur_port];
}
if (exit_streams[cur_port] > 0) {
uint32_t num = round_uint32_to_next_multiple_of(
exit_streams[cur_port],
EXIT_STATS_ROUND_UP_STREAMS);
- buf = NULL;
- tor_asprintf(&buf, "%d=%u", cur_port, num);
- smartlist_add(streams_strings, buf);
+ smartlist_add_asprintf(streams_strings, "%d=%u", cur_port, num);
other_streams -= exit_streams[cur_port];
}
}
@@ -2234,20 +2228,16 @@ rep_hist_format_exit_stats(time_t now)
other_written = round_uint64_to_next_multiple_of(other_written,
EXIT_STATS_ROUND_UP_BYTES);
other_written /= 1024;
- buf = NULL;
- tor_asprintf(&buf, "other="U64_FORMAT, U64_PRINTF_ARG(other_written));
- smartlist_add(written_strings, buf);
+ smartlist_add_asprintf(written_strings, "other="U64_FORMAT,
+ U64_PRINTF_ARG(other_written));
other_read = round_uint64_to_next_multiple_of(other_read,
EXIT_STATS_ROUND_UP_BYTES);
other_read /= 1024;
- buf = NULL;
- tor_asprintf(&buf, "other="U64_FORMAT, U64_PRINTF_ARG(other_read));
- smartlist_add(read_strings, buf);
+ smartlist_add_asprintf(read_strings, "other="U64_FORMAT,
+ U64_PRINTF_ARG(other_read));
other_streams = round_uint32_to_next_multiple_of(other_streams,
EXIT_STATS_ROUND_UP_STREAMS);
- buf = NULL;
- tor_asprintf(&buf, "other=%u", other_streams);
- smartlist_add(streams_strings, buf);
+ smartlist_add_asprintf(streams_strings, "other=%u", other_streams);
/* Join all observations in single strings. */
written_string = smartlist_join_strings(written_strings, ",", 0, NULL);
@@ -2468,7 +2458,6 @@ rep_hist_format_buffer_stats(time_t now)
int processed_cells[SHARES], circs_in_share[SHARES],
number_of_circuits, i;
double queued_cells[SHARES], time_in_queue[SHARES];
- char *buf = NULL;
smartlist_t *processed_cells_strings, *queued_cells_strings,
*time_in_queue_strings;
char *processed_cells_string, *queued_cells_string,
@@ -2510,19 +2499,19 @@ rep_hist_format_buffer_stats(time_t now)
queued_cells_strings = smartlist_create();
time_in_queue_strings = smartlist_create();
for (i = 0; i < SHARES; i++) {
- tor_asprintf(&buf,"%d", !circs_in_share[i] ? 0 :
- processed_cells[i] / circs_in_share[i]);
- smartlist_add(processed_cells_strings, buf);
+ smartlist_add_asprintf(processed_cells_strings,
+ "%d", !circs_in_share[i] ? 0 :
+ processed_cells[i] / circs_in_share[i]);
}
for (i = 0; i < SHARES; i++) {
- tor_asprintf(&buf, "%.2f", circs_in_share[i] == 0 ? 0.0 :
- queued_cells[i] / (double) circs_in_share[i]);
- smartlist_add(queued_cells_strings, buf);
+ smartlist_add_asprintf(queued_cells_strings, "%.2f",
+ circs_in_share[i] == 0 ? 0.0 :
+ queued_cells[i] / (double) circs_in_share[i]);
}
for (i = 0; i < SHARES; i++) {
- tor_asprintf(&buf, "%.0f", circs_in_share[i] == 0 ? 0.0 :
- time_in_queue[i] / (double) circs_in_share[i]);
- smartlist_add(time_in_queue_strings, buf);
+ smartlist_add_asprintf(time_in_queue_strings, "%.0f",
+ circs_in_share[i] == 0 ? 0.0 :
+ time_in_queue[i] / (double) circs_in_share[i]);
}
/* Join all observations in single strings. */
diff --git a/src/or/router.c b/src/or/router.c
index b2df3834f..7d9d2724f 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -2267,9 +2267,7 @@ extrainfo_dump_to_string(char **s_out, extrainfo_t *extrainfo,
smartlist_add(chunks, pre);
if (geoip_is_loaded()) {
- char *chunk=NULL;
- tor_asprintf(&chunk, "geoip-db-digest %s\n", geoip_db_digest());
- smartlist_add(chunks, chunk);
+ smartlist_add_asprintf(chunks, "geoip-db-digest %s\n", geoip_db_digest());
}
if (options->ExtraInfoStatistics && write_stats_to_extrainfo) {
diff --git a/src/or/transports.c b/src/or/transports.c
index abf9d884f..d8d2ff6aa 100644
--- a/src/or/transports.c
+++ b/src/or/transports.c
@@ -918,7 +918,7 @@ parse_cmethod_line(const char *line, managed_proxy_t *mp)
static char *
get_bindaddr_for_proxy(const managed_proxy_t *mp)
{
- char *bindaddr = NULL;
+ char *bindaddr_result = NULL;
char *bindaddr_tmp = NULL;
smartlist_t *string_tmp = smartlist_create();
@@ -927,18 +927,17 @@ get_bindaddr_for_proxy(const managed_proxy_t *mp)
SMARTLIST_FOREACH_BEGIN(mp->transports_to_launch, char *, t) {
bindaddr_tmp = get_bindaddr_for_transport(t);
- tor_asprintf(&bindaddr, "%s-%s", t, bindaddr_tmp);
- smartlist_add(string_tmp, bindaddr);
+ smartlist_add_asprintf(string_tmp, "%s-%s", t, bindaddr_tmp);
tor_free(bindaddr_tmp);
} SMARTLIST_FOREACH_END(t);
- bindaddr = smartlist_join_strings(string_tmp, ",", 0, NULL);
+ bindaddr_result = smartlist_join_strings(string_tmp, ",", 0, NULL);
SMARTLIST_FOREACH(string_tmp, char *, t, tor_free(t));
smartlist_free(string_tmp);
- return bindaddr;
+ return bindaddr_result;
}
#ifdef MS_WINDOWS