diff options
author | Nick Mathewson <nickm@torproject.org> | 2016-05-25 16:40:51 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2016-05-25 16:40:51 -0400 |
commit | 28cbcd033cadc9dfcabf4e179fc3649d8ec595e2 (patch) | |
tree | b1b19723c30e7e49c324795af0d86470159ddb37 /src/or/routerlist.c | |
parent | 44ea3dc3311564a9b7f6f67a106be0fa56b38554 (diff) | |
parent | f2d614c3d93aceac4954f7cd593213a5fcfbb123 (diff) | |
download | tor-28cbcd033cadc9dfcabf4e179fc3649d8ec595e2.tar.gz tor-28cbcd033cadc9dfcabf4e179fc3649d8ec595e2.zip |
Merge branch 'maint-0.2.8'
Diffstat (limited to 'src/or/routerlist.c')
-rw-r--r-- | src/or/routerlist.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/or/routerlist.c b/src/or/routerlist.c index dd16e4b06b..4d9d249d10 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -2994,6 +2994,19 @@ signed_descriptor_free(signed_descriptor_t *sd) tor_free(sd); } +/** Copy src into dest, and steal all references inside src so that when + * we free src, we don't mess up dest. */ +static void +signed_descriptor_move(signed_descriptor_t *dest, + signed_descriptor_t *src) +{ + tor_assert(dest != src); + memcpy(dest, src, sizeof(signed_descriptor_t)); + src->signed_descriptor_body = NULL; + src->signing_key_cert = NULL; + dest->routerlist_index = -1; +} + /** Extract a signed_descriptor_t from a general routerinfo, and free the * routerinfo. */ @@ -3003,10 +3016,7 @@ signed_descriptor_from_routerinfo(routerinfo_t *ri) signed_descriptor_t *sd; tor_assert(ri->purpose == ROUTER_PURPOSE_GENERAL); sd = tor_malloc_zero(sizeof(signed_descriptor_t)); - memcpy(sd, &(ri->cache_info), sizeof(signed_descriptor_t)); - sd->routerlist_index = -1; - ri->cache_info.signed_descriptor_body = NULL; - ri->cache_info.signing_key_cert = NULL; + signed_descriptor_move(sd, &ri->cache_info); routerinfo_free(ri); return sd; } @@ -3492,9 +3502,7 @@ routerlist_reparse_old(routerlist_t *rl, signed_descriptor_t *sd) 0, 1, NULL, NULL); if (!ri) return NULL; - memcpy(&ri->cache_info, sd, sizeof(signed_descriptor_t)); - sd->signed_descriptor_body = NULL; /* Steal reference. */ - ri->cache_info.routerlist_index = -1; + signed_descriptor_move(&ri->cache_info, sd); routerlist_remove_old(rl, sd, -1); |