summaryrefslogtreecommitdiff
path: root/src/or/directory.c
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/directory.c
parent9c6d913b9e1b84ffcefb2cbd9cfe6f7bd15fc9b3 (diff)
downloadtor-edcc9981d8b8894d2ef4e0d617a20d7d99547817.tar.gz
tor-edcc9981d8b8894d2ef4e0d617a20d7d99547817.zip
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/directory.c')
-rw-r--r--src/or/directory.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/or/directory.c b/src/or/directory.c
index 12636bac33..8087d7603d 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));