From: Nick Mathewson Date: Mon, 10 Jan 2011 18:15:51 +0000 (-0500) Subject: On bwhist state load failure, clear dir_read/write hist too X-Git-Tag: tor-0.2.2.23-alpha~9^2^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=28844c8403f16f184c185798c78dcd6a959450a3;p=thirdparty%2Ftor.git On bwhist state load failure, clear dir_read/write hist too --- diff --git a/changes/1863_bwhist b/changes/1863_bwhist index c1d4d866ce..b9e8ef4c52 100644 --- a/changes/1863_bwhist +++ b/changes/1863_bwhist @@ -3,3 +3,8 @@ triggered if a future version of Tor ever changed the timing granularity at which bandwidth history is measured. Bugfix on Tor 0.1.1.11-alpha. + - Correctly clear out dir_read/dir_write history when there is an + error parsing any bw history value from the state file. Bugfix on + Tor 0.2.2.15-alpha. + + diff --git a/src/or/rephist.c b/src/or/rephist.c index 5a3a15edbc..f0dd45128c 100644 --- a/src/or/rephist.c +++ b/src/or/rephist.c @@ -1293,10 +1293,15 @@ static bw_array_t *dir_read_array = NULL; directory protocol. */ static bw_array_t *dir_write_array = NULL; -/** Set up [dir-]read_array and [dir-]write_array. */ +/** Set up [dir-]read_array and [dir-]write_array, freeing them if they alrady + * exist. */ static void bw_arrays_init(void) { + tor_free(read_array); + tor_free(write_array); + tor_free(dir_read_array); + tor_free(dir_write_array); read_array = bw_array_new(); write_array = bw_array_new(); dir_read_array = bw_array_new(); @@ -1627,11 +1632,7 @@ rep_hist_load_state(or_state_t *state, char **err) if (!all_ok) { *err = tor_strdup("Parsing of bandwidth history values failed"); /* and create fresh arrays */ - tor_free(read_array); - tor_free(write_array); - - read_array = bw_array_new(); - write_array = bw_array_new(); + bw_arrays_init(); return -1; } return 0;