Merge commit 'sebastian/bug1831'

This commit is contained in:
Nick Mathewson 2010-08-15 23:43:36 -04:00
commit a856f446c7
16 changed files with 51 additions and 38 deletions

8
changes/bug1831 Normal file
View File

@ -0,0 +1,8 @@
o Minor bugfixes
- Fix a memory leak in the error case of circuit_build_times_parse_state().
Bugfix on 0.2.2.14-alpha; fixes bug 1831 partially.
- Fix a memory leak in dirvote_add_signatures_to_pending_consensus().
Bugfix on 0.2.2.6-alpha; fixes bug 1831 partially.
- Fix a memory leak in dirvote_compute_consensuses().
Bugfix on 0.2.0.3-alpha; fixes bug 1831 partially.

View File

@ -20,6 +20,10 @@ for $fn (@ARGV) {
if (/\t/) { if (/\t/) {
print " TAB:$fn:$.\n"; print " TAB:$fn:$.\n";
} }
## Warn about markers that don't have a space in front of them
if (/^[a-zA-Z_][a-zA-Z_0-9]*:/) {
print "nosplabel:$fn:$.\n";
}
## Warn about trailing whitespace. ## Warn about trailing whitespace.
if (/ +$/) { if (/ +$/) {
print "Space\@EOL:$fn:$.\n"; print "Space\@EOL:$fn:$.\n";

View File

@ -605,11 +605,11 @@ circuit_build_times_filter_timeouts(circuit_build_times_t *cbt)
* after we do so. Use this result to estimate parameters and * after we do so. Use this result to estimate parameters and
* calculate the timeout. * calculate the timeout.
* *
* Returns -1 and sets msg on error. Msg must be freed by the caller. * Return -1 on error.
*/ */
int int
circuit_build_times_parse_state(circuit_build_times_t *cbt, circuit_build_times_parse_state(circuit_build_times_t *cbt,
or_state_t *state, char **msg) or_state_t *state)
{ {
int tot_values = 0; int tot_values = 0;
uint32_t loaded_cnt = 0, N = 0; uint32_t loaded_cnt = 0, N = 0;
@ -617,7 +617,7 @@ circuit_build_times_parse_state(circuit_build_times_t *cbt,
unsigned int i; unsigned int i;
build_time_t *loaded_times; build_time_t *loaded_times;
circuit_build_times_init(cbt); circuit_build_times_init(cbt);
*msg = NULL; int err = 0;
if (circuit_build_times_disabled()) { if (circuit_build_times_disabled()) {
return 0; return 0;
@ -631,8 +631,9 @@ circuit_build_times_parse_state(circuit_build_times_t *cbt,
smartlist_split_string(args, line->value, " ", smartlist_split_string(args, line->value, " ",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0); SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
if (smartlist_len(args) < 2) { if (smartlist_len(args) < 2) {
*msg = tor_strdup("Unable to parse circuit build times: " log_warn(LD_GENERAL, "Unable to parse circuit build times: "
"Too few arguments to CircuitBuildTime"); "Too few arguments to CircuitBuildTime");
err = 1;
SMARTLIST_FOREACH(args, char*, cp, tor_free(cp)); SMARTLIST_FOREACH(args, char*, cp, tor_free(cp));
smartlist_free(args); smartlist_free(args);
break; break;
@ -645,8 +646,9 @@ circuit_build_times_parse_state(circuit_build_times_t *cbt,
ms = (build_time_t)tor_parse_ulong(ms_str, 0, 0, ms = (build_time_t)tor_parse_ulong(ms_str, 0, 0,
CBT_BUILD_TIME_MAX, &ok, NULL); CBT_BUILD_TIME_MAX, &ok, NULL);
if (!ok) { if (!ok) {
*msg = tor_strdup("Unable to parse circuit build times: " log_warn(LD_GENERAL, "Unable to parse circuit build times: "
"Unparsable bin number"); "Unparsable bin number");
err = 1;
SMARTLIST_FOREACH(args, char*, cp, tor_free(cp)); SMARTLIST_FOREACH(args, char*, cp, tor_free(cp));
smartlist_free(args); smartlist_free(args);
break; break;
@ -654,8 +656,9 @@ circuit_build_times_parse_state(circuit_build_times_t *cbt,
count = (uint32_t)tor_parse_ulong(count_str, 0, 0, count = (uint32_t)tor_parse_ulong(count_str, 0, 0,
UINT32_MAX, &ok, NULL); UINT32_MAX, &ok, NULL);
if (!ok) { if (!ok) {
*msg = tor_strdup("Unable to parse circuit build times: " log_warn(LD_GENERAL, "Unable to parse circuit build times: "
"Unparsable bin count"); "Unparsable bin count");
err = 1;
SMARTLIST_FOREACH(args, char*, cp, tor_free(cp)); SMARTLIST_FOREACH(args, char*, cp, tor_free(cp));
smartlist_free(args); smartlist_free(args);
break; break;
@ -692,10 +695,9 @@ circuit_build_times_parse_state(circuit_build_times_t *cbt,
"Corrupt state file? Build times count mismatch. " "Corrupt state file? Build times count mismatch. "
"Read %d times, but file says %d", loaded_cnt, "Read %d times, but file says %d", loaded_cnt,
state->TotalBuildTimes); state->TotalBuildTimes);
*msg = tor_strdup("Build times count mismatch."); err = 1;
circuit_build_times_reset(cbt); circuit_build_times_reset(cbt);
tor_free(loaded_times); goto done;
return -1;
} }
circuit_build_times_shuffle_and_store_array(cbt, loaded_times, loaded_cnt); circuit_build_times_shuffle_and_store_array(cbt, loaded_times, loaded_cnt);
@ -716,10 +718,9 @@ circuit_build_times_parse_state(circuit_build_times_t *cbt,
"Corrupt state file? Shuffled build times mismatch. " "Corrupt state file? Shuffled build times mismatch. "
"Read %d times, but file says %d", tot_values, "Read %d times, but file says %d", tot_values,
state->TotalBuildTimes); state->TotalBuildTimes);
*msg = tor_strdup("Build times count mismatch."); err = 1;
circuit_build_times_reset(cbt); circuit_build_times_reset(cbt);
tor_free(loaded_times); goto done;
return -1;
} }
circuit_build_times_set_timeout(cbt); circuit_build_times_set_timeout(cbt);
@ -728,8 +729,9 @@ circuit_build_times_parse_state(circuit_build_times_t *cbt,
circuit_build_times_filter_timeouts(cbt); circuit_build_times_filter_timeouts(cbt);
} }
done:
tor_free(loaded_times); tor_free(loaded_times);
return *msg ? -1 : 0; return err ? -1 : 0;
} }
/** /**

View File

@ -81,7 +81,7 @@ extern circuit_build_times_t circ_times;
void circuit_build_times_update_state(circuit_build_times_t *cbt, void circuit_build_times_update_state(circuit_build_times_t *cbt,
or_state_t *state); or_state_t *state);
int circuit_build_times_parse_state(circuit_build_times_t *cbt, int circuit_build_times_parse_state(circuit_build_times_t *cbt,
or_state_t *state, char **msg); or_state_t *state);
void circuit_build_times_count_timeout(circuit_build_times_t *cbt, void circuit_build_times_count_timeout(circuit_build_times_t *cbt,
int did_onehop); int did_onehop);
int circuit_build_times_count_close(circuit_build_times_t *cbt, int circuit_build_times_count_close(circuit_build_times_t *cbt,

View File

@ -4971,9 +4971,7 @@ or_state_set(or_state_t *new_state)
tor_free(err); tor_free(err);
ret = -1; ret = -1;
} }
if (circuit_build_times_parse_state(&circ_times, global_state, &err) < 0) { if (circuit_build_times_parse_state(&circ_times, global_state) < 0) {
log_warn(LD_GENERAL,"%s",err);
tor_free(err);
ret = -1; ret = -1;
} }
return ret; return ret;

View File

@ -2942,6 +2942,7 @@ dirvote_compute_consensuses(void)
strlen(pending_consensus_signatures), 0); strlen(pending_consensus_signatures), 0);
log_notice(LD_DIR, "Signature(s) posted."); log_notice(LD_DIR, "Signature(s) posted.");
smartlist_free(votes);
return 0; return 0;
err: err:
smartlist_free(votes); smartlist_free(votes);
@ -3008,6 +3009,7 @@ dirvote_add_signatures_to_pending_consensus(
networkstatus_vote_free(v); networkstatus_vote_free(v);
} }
*msg_out = "Signatures added"; *msg_out = "Signatures added";
tor_free(new_signatures);
} else if (r == 0) { } else if (r == 0) {
*msg_out = "Signatures ignored"; *msg_out = "Signatures ignored";
} else { } else {
@ -3137,7 +3139,7 @@ void
dirvote_free_all(void) dirvote_free_all(void)
{ {
dirvote_clear_votes(1); dirvote_clear_votes(1);
/* now empty as a result of clear_pending_votes. */ /* now empty as a result of dirvote_clear_votes(). */
smartlist_free(pending_vote_list); smartlist_free(pending_vote_list);
pending_vote_list = NULL; pending_vote_list = NULL;
smartlist_free(previous_vote_list); smartlist_free(previous_vote_list);
@ -3146,7 +3148,7 @@ dirvote_free_all(void)
dirvote_clear_pending_consensuses(); dirvote_clear_pending_consensuses();
tor_free(pending_consensus_signatures); tor_free(pending_consensus_signatures);
if (pending_consensus_signature_list) { if (pending_consensus_signature_list) {
/* now empty as a result of clear_pending_votes. */ /* now empty as a result of dirvote_clear_votes(). */
smartlist_free(pending_consensus_signature_list); smartlist_free(pending_consensus_signature_list);
pending_consensus_signature_list = NULL; pending_consensus_signature_list = NULL;
} }

View File

@ -485,7 +485,6 @@ test_circuit_timeout(void)
circuit_build_times_t final; circuit_build_times_t final;
double timeout1, timeout2; double timeout1, timeout2;
or_state_t state; or_state_t state;
char *msg;
int i, runs; int i, runs;
double close_ms; double close_ms;
circuit_build_times_init(&initial); circuit_build_times_init(&initial);
@ -525,7 +524,7 @@ test_circuit_timeout(void)
test_assert(estimate.total_build_times <= CBT_NCIRCUITS_TO_OBSERVE); test_assert(estimate.total_build_times <= CBT_NCIRCUITS_TO_OBSERVE);
circuit_build_times_update_state(&estimate, &state); circuit_build_times_update_state(&estimate, &state);
test_assert(circuit_build_times_parse_state(&final, &state, &msg) == 0); test_assert(circuit_build_times_parse_state(&final, &state) == 0);
circuit_build_times_update_alpha(&final); circuit_build_times_update_alpha(&final);
timeout2 = circuit_build_times_calculate_timeout(&final, timeout2 = circuit_build_times_calculate_timeout(&final,