summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Færøy <ahf@torproject.org>2017-05-22 14:42:18 +0000
committerAlexander Færøy <ahf@torproject.org>2017-05-22 14:42:18 +0000
commit2b26ac139086c4ce3067b6d27644cb37808a9eb0 (patch)
treef3e0945a2f90f53826d8bd49dbe4d60997f04094
parent26795da900d7b487b80e19b804475ad7b132188d (diff)
downloadtor-2b26ac139086c4ce3067b6d27644cb37808a9eb0.tar.gz
tor-2b26ac139086c4ce3067b6d27644cb37808a9eb0.zip
Refactor error path handling in connection_dir_client_reached_eof().
This patch lifts the return value, rv, variable to the beginning of the function, adds a 'done' label for clean-up and function exit and makes the rest of the function use the rv value + goto done; instead of cleaning up in multiple places. See: https://bugs.torproject.org/22305
-rw-r--r--src/or/directory.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/or/directory.c b/src/or/directory.c
index 5aab8a7328..495fd9c62a 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -2204,8 +2204,8 @@ static int handle_response_upload_renddesc_v2(dir_connection_t *,
static int
connection_dir_client_reached_eof(dir_connection_t *conn)
{
- char *body;
- char *headers;
+ char *body = NULL;
+ char *headers = NULL;
char *reason = NULL;
size_t body_len = 0;
int status_code;
@@ -2214,6 +2214,7 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
compress_method_t compression;
int plausible;
int skewed = 0;
+ int rv;
int allow_partial = (conn->base_.purpose == DIR_PURPOSE_FETCH_SERVERDESC ||
conn->base_.purpose == DIR_PURPOSE_FETCH_EXTRAINFO ||
conn->base_.purpose == DIR_PURPOSE_FETCH_MICRODESC);
@@ -2241,8 +2242,9 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
&compression, &reason) < 0) {
log_warn(LD_HTTP,"Unparseable headers (server '%s:%d'). Closing.",
conn->base_.address, conn->base_.port);
- tor_free(body); tor_free(headers);
- return -1;
+
+ rv = -1;
+ goto done;
}
if (!reason) reason = tor_strdup("[no reason given]");
@@ -2316,8 +2318,8 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
if ((ds = router_get_fallback_dirserver_by_digest(id_digest)))
ds->fake_status.last_dir_503_at = now;
- tor_free(body); tor_free(headers); tor_free(reason);
- return -1;
+ rv = -1;
+ goto done;
}
plausible = body_is_plausible(body, body_len, conn->base_.purpose);
@@ -2362,8 +2364,8 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
log_fn(LOG_PROTOCOL_WARN, LD_HTTP,
"Unable to decompress HTTP body (server '%s:%d').",
conn->base_.address, conn->base_.port);
- tor_free(body); tor_free(headers); tor_free(reason);
- return -1;
+ rv = -1;
+ goto done;
}
if (new_body) {
tor_free(body);
@@ -2372,7 +2374,6 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
}
}
- int rv;
response_handler_args_t args;
memset(&args, 0, sizeof(args));
args.status_code = status_code;
@@ -2421,6 +2422,8 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
rv = -1;
break;
}
+
+ done:
tor_free(body);
tor_free(headers);
tor_free(reason);