Commit a42adce3 authored by Nick Mathewson's avatar Nick Mathewson 🎨
Browse files

fix memory leak in router.c; start relying on NULL==(zero bytes)


svn:r2538
parent b0afd91a
......@@ -1200,8 +1200,7 @@ crypto_dh_env_t *crypto_dh_new()
if (!dh_param_p)
init_dh_param();
res = tor_malloc(sizeof(crypto_dh_env_t));
res->dh = NULL;
res = tor_malloc_zero(sizeof(crypto_dh_env_t));
if (!(res->dh = DH_new()))
goto err;
......
......@@ -492,22 +492,13 @@ static void
init_options(or_options_t *options)
{
memset(options,0,sizeof(or_options_t));
options->LogOptions = NULL;
options->ExitNodes = tor_strdup("");
options->EntryNodes = tor_strdup("");
options->StrictEntryNodes = options->StrictExitNodes = 0;
options->ExcludeNodes = tor_strdup("");
options->RendNodes = tor_strdup("");
options->RendExcludeNodes = tor_strdup("");
options->ExitPolicy = NULL;
options->SocksPolicy = NULL;
options->SocksBindAddress = NULL;
options->ORBindAddress = NULL;
options->DirBindAddress = NULL;
options->OutboundBindAddress = NULL;
options->RecommendedVersions = NULL;
options->PidFile = NULL; // tor_strdup("tor.pid");
options->DataDirectory = NULL;
/* options->PidFile = tor_strdup("tor.pid"); */
options->PathlenCoinWeight = 0.3;
options->MaxConn = 900;
options->DirFetchPostPeriod = 600;
......@@ -517,11 +508,6 @@ init_options(or_options_t *options)
options->BandwidthRate = 800000; /* at most 800kB/s total sustained incoming */
options->BandwidthBurst = 10000000; /* max burst on the token bucket */
options->NumCpus = 1;
options->RendConfigLines = NULL;
options->FirewallPorts = NULL;
options->DirServers = NULL;
options->MyFamily = NULL;
options->NodeFamilies = NULL;
}
static char *
......
......@@ -243,7 +243,6 @@ int dns_resolve(connection_t *exitconn) {
/* add us to the pending list */
pending_connection = tor_malloc_zero(sizeof(struct pending_connection_t));
pending_connection->conn = exitconn;
pending_connection->next = NULL;
resolve->pending_connections = pending_connection;
exitconn->state = EXIT_CONN_STATE_RESOLVING;
......
......@@ -29,9 +29,8 @@ static int ol_length=0;
int onion_pending_add(circuit_t *circ) {
struct onion_queue_t *tmp;
tmp = tor_malloc(sizeof(struct onion_queue_t));
tmp = tor_malloc_zero(sizeof(struct onion_queue_t));
tmp->circ = circ;
tmp->next = NULL;
if(!ol_tail) {
tor_assert(!ol_list);
......
......@@ -547,7 +547,6 @@ int router_rebuild_descriptor(void) {
ri->bandwidthrate = options.BandwidthRate;
ri->bandwidthburst = options.BandwidthBurst;
ri->bandwidthcapacity = router_get_bandwidth_capacity();
ri->exit_policy = NULL; /* zero it out first */
router_add_exit_policy_from_config(ri);
ri->is_trusted_dir = authdir_mode();
if(desc_routerinfo) /* inherit values */
......@@ -556,8 +555,6 @@ int router_rebuild_descriptor(void) {
ri->declared_family = smartlist_create();
smartlist_split_string(ri->declared_family, options.MyFamily, ",",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
} else {
ri->declared_family = NULL;
}
if (desc_routerinfo)
......@@ -684,7 +681,7 @@ int router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
(int) router->bandwidthcapacity,
onion_pkey, identity_pkey,
family_line, bandwidth_usage);
tor_free(family_line);
tor_free(onion_pkey);
tor_free(identity_pkey);
tor_free(bandwidth_usage);
......
......@@ -718,9 +718,8 @@ router_parse_list_from_string(const char **s, routerlist_t **dest,
if (*dest)
routerlist_free(*dest);
*dest = tor_malloc(sizeof(routerlist_t));
*dest = tor_malloc_zero(sizeof(routerlist_t));
(*dest)->routers = routers;
(*dest)->software_versions = NULL;
return 0;
}
......@@ -770,8 +769,6 @@ routerinfo_t *router_parse_entry_from_string(const char *s,
}
router = tor_malloc_zero(sizeof(routerinfo_t));
router->onion_pkey = router->identity_pkey = NULL;
router->declared_family = NULL;
ports_set = bw_set = 0;
if (tok->n_args == 2 || tok->n_args == 5 || tok->n_args == 6) {
......@@ -1122,7 +1119,6 @@ router_parse_exit_policy(directory_token_t *tok) {
address, inet_ntoa(in), newe->prt_min, newe->prt_max);
tor_free(address);
newe->next = NULL;
return newe;
policy_read_failed:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment