diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-04-26 00:10:04 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-04-26 00:10:04 -0400 |
commit | c7951731ed1bcc06d1eb404bd699cc0e0392e626 (patch) | |
tree | 9622bfee17298b716e3ea7dc3a9c1fa093704d5f /src/or/statefile.c | |
parent | d2147cc7ba5c5d5114bae61000cbf757353c3ed6 (diff) | |
download | tor-c7951731ed1bcc06d1eb404bd699cc0e0392e626.tar.gz tor-c7951731ed1bcc06d1eb404bd699cc0e0392e626.zip |
Fix memory leaks in test_circuit_timeout
Found with valgrind.
Diffstat (limited to 'src/or/statefile.c')
-rw-r--r-- | src/or/statefile.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/or/statefile.c b/src/or/statefile.c index da31341712..a50eae5ff4 100644 --- a/src/or/statefile.c +++ b/src/or/statefile.c @@ -294,6 +294,16 @@ or_state_save_broken(char *fname) tor_free(fname2); } +STATIC or_state_t * +or_state_new(void) +{ + or_state_t *new_state = tor_malloc_zero(sizeof(or_state_t)); + new_state->magic_ = OR_STATE_MAGIC; + config_init(&state_format, new_state); + + return new_state; +} + /** Reload the persistent state from disk, generating a new state as needed. * Return 0 on success, less than 0 on failure. */ @@ -321,9 +331,7 @@ or_state_load(void) log_warn(LD_GENERAL,"State file \"%s\" is not a file? Failing.", fname); goto done; } - new_state = tor_malloc_zero(sizeof(or_state_t)); - new_state->magic_ = OR_STATE_MAGIC; - config_init(&state_format, new_state); + new_state = or_state_new(); if (contents) { config_line_t *lines=NULL; int assign_retval; @@ -358,9 +366,7 @@ or_state_load(void) tor_free(contents); config_free(&state_format, new_state); - new_state = tor_malloc_zero(sizeof(or_state_t)); - new_state->magic_ = OR_STATE_MAGIC; - config_init(&state_format, new_state); + new_state = or_state_new(); } else if (contents) { log_info(LD_GENERAL, "Loaded state from \"%s\"", fname); } else { @@ -625,10 +631,19 @@ save_transport_to_state(const char *transport, tor_free(transport_addrport); } +STATIC void +or_state_free(or_state_t *state) +{ + if (!state) + return; + + config_free(&state_format, state); +} + void or_state_free_all(void) { - config_free(&state_format, global_state); + or_state_free(global_state); global_state = NULL; } |