prefer tor_free to free

plus complain more loudly when we fail to parse a dir we just fetched


svn:r2401
This commit is contained in:
Roger Dingledine 2004-09-29 06:52:36 +00:00
parent 6ed095b177
commit 136d4e5739
10 changed files with 26 additions and 28 deletions

View File

@ -124,7 +124,7 @@ static void circuit_free(circuit_t *circ) {
} }
memset(circ, 0xAA, sizeof(circuit_t)); /* poison memory */ memset(circ, 0xAA, sizeof(circuit_t)); /* poison memory */
free(circ); tor_free(circ);
} }
/** Deallocate space associated with the linked list <b>cpath</b>. */ /** Deallocate space associated with the linked list <b>cpath</b>. */
@ -158,7 +158,7 @@ void circuit_free_cpath_node(crypt_path_t *victim) {
crypto_free_digest_env(victim->b_digest); crypto_free_digest_env(victim->b_digest);
if(victim->handshake_state) if(victim->handshake_state)
crypto_dh_free(victim->handshake_state); crypto_dh_free(victim->handshake_state);
free(victim); tor_free(victim);
} }
/** Return a circ such that: /** Return a circ such that:

View File

@ -114,9 +114,9 @@ static void config_free_lines(struct config_line_t *front) {
tmp = front; tmp = front;
front = tmp->next; front = tmp->next;
free(tmp->key); tor_free(tmp->key);
free(tmp->value); tor_free(tmp->value);
free(tmp); tor_free(tmp);
} }
} }

View File

@ -158,7 +158,7 @@ void connection_free(connection_t *conn) {
tor_close_socket(conn->s); tor_close_socket(conn->s);
} }
memset(conn, 0xAA, sizeof(connection_t)); /* poison memory */ memset(conn, 0xAA, sizeof(connection_t)); /* poison memory */
free(conn); tor_free(conn);
} }
/** Call connection_free() on every connection in our array. /** Call connection_free() on every connection in our array.

View File

@ -400,7 +400,7 @@ connection_dir_client_reached_eof(connection_t *conn)
if(parse_http_response(headers, &status_code, NULL, &date_header, if(parse_http_response(headers, &status_code, NULL, &date_header,
&compression) < 0) { &compression) < 0) {
log_fn(LOG_WARN,"Unparseable headers. Closing."); log_fn(LOG_WARN,"Unparseable headers. Closing.");
free(body); free(headers); tor_free(body); tor_free(headers);
return -1; return -1;
} }
if (date_header > 0) { if (date_header > 0) {
@ -433,17 +433,17 @@ connection_dir_client_reached_eof(connection_t *conn)
log_fn(LOG_INFO,"Received directory (size %d):\n%s", body_len, body); log_fn(LOG_INFO,"Received directory (size %d):\n%s", body_len, body);
if(status_code == 503 || body_len == 0) { if(status_code == 503 || body_len == 0) {
log_fn(LOG_INFO,"Empty directory. Ignoring."); log_fn(LOG_INFO,"Empty directory. Ignoring.");
free(body); free(headers); tor_free(body); tor_free(headers);
return 0; return 0;
} }
if(status_code != 200) { if(status_code != 200) {
log_fn(LOG_WARN,"Received http status code %d from dirserver. Failing.", log_fn(LOG_WARN,"Received http status code %d from dirserver. Failing.",
status_code); status_code);
free(body); free(headers); tor_free(body); tor_free(headers);
return -1; return -1;
} }
if(router_load_routerlist_from_directory(body, NULL) < 0){ if(router_load_routerlist_from_directory(body, NULL) < 0){
log_fn(LOG_INFO,"...but parsing failed. Ignoring."); log_fn(LOG_WARN,"I failed to parse the directory I fetched from %s:%d. Ignoring.", conn->address, conn->port);
} else { } else {
log_fn(LOG_INFO,"updated routers."); log_fn(LOG_INFO,"updated routers.");
} }
@ -458,12 +458,12 @@ connection_dir_client_reached_eof(connection_t *conn)
if(status_code != 200) { if(status_code != 200) {
log_fn(LOG_WARN,"Received http status code %d from dirserver. Failing.", log_fn(LOG_WARN,"Received http status code %d from dirserver. Failing.",
status_code); status_code);
free(body); free(headers); tor_free(body); tor_free(headers);
return -1; return -1;
} }
if (!(rrs = router_parse_runningrouters(body))) { if (!(rrs = router_parse_runningrouters(body))) {
log_fn(LOG_WARN, "Can't parse runningrouters list"); log_fn(LOG_WARN, "Can't parse runningrouters list");
free(body); free(headers); tor_free(body); tor_free(headers);
return -1; return -1;
} }
router_get_routerlist(&rl); router_get_routerlist(&rl);
@ -526,7 +526,7 @@ connection_dir_client_reached_eof(connection_t *conn)
break; break;
} }
} }
free(body); free(headers); tor_free(body); tor_free(headers);
return 0; return 0;
} }

View File

@ -275,7 +275,7 @@ static void free_descriptor_entry(descriptor_entry_t *desc)
tor_free(desc->descriptor); tor_free(desc->descriptor);
tor_free(desc->nickname); tor_free(desc->nickname);
routerinfo_free(desc->router); routerinfo_free(desc->router);
free(desc); tor_free(desc);
} }
/** Release all storage that the dirserv is holding for server /** Release all storage that the dirserv is holding for server
@ -594,7 +594,7 @@ dirserv_dump_directory_to_string(char *s, unsigned int maxlen,
"running-routers %s\n\n", "running-routers %s\n\n",
published, options.RecommendedVersions, cp); published, options.RecommendedVersions, cp);
free(cp); tor_free(cp);
i = strlen(s); i = strlen(s);
cp = s+i; cp = s+i;
@ -749,7 +749,7 @@ static int dirserv_regenerate_directory(void)
tor_cleanup(); tor_cleanup();
exit(0); exit(0);
} }
free(new_directory); tor_free(new_directory);
if(get_data_directory(&options)) { if(get_data_directory(&options)) {
snprintf(filename,sizeof(filename),"%s/cached-directory", get_data_directory(&options)); snprintf(filename,sizeof(filename),"%s/cached-directory", get_data_directory(&options));
if(write_str_to_file(filename,the_directory,0) < 0) { if(write_str_to_file(filename,the_directory,0) < 0) {

View File

@ -297,7 +297,6 @@ static void conn_write(int i) {
static void conn_close_if_marked(int i) { static void conn_close_if_marked(int i) {
connection_t *conn; connection_t *conn;
int retval; int retval;
struct in_addr in;
conn = connection_array[i]; conn = connection_array[i];
assert_connection_ok(conn, time(NULL)); assert_connection_ok(conn, time(NULL));
@ -309,12 +308,11 @@ static void conn_close_if_marked(int i) {
if(conn->s >= 0 && connection_wants_to_flush(conn)) { if(conn->s >= 0 && connection_wants_to_flush(conn)) {
/* -1 means it's an incomplete edge connection, or that the socket /* -1 means it's an incomplete edge connection, or that the socket
* has already been closed as unflushable. */ * has already been closed as unflushable. */
in.s_addr = htonl(conn->addr);
if(!conn->hold_open_until_flushed) if(!conn->hold_open_until_flushed)
log_fn(LOG_INFO, log_fn(LOG_INFO,
"Conn (addr %s, fd %d, type %s, state %d) marked, but wants to flush %d bytes. " "Conn (addr %s, fd %d, type %s, state %d) marked, but wants to flush %d bytes. "
"(Marked at %s:%d)", "(Marked at %s:%d)",
inet_ntoa(in), conn->s, CONN_TYPE_TO_STRING(conn->type), conn->state, conn->address, conn->s, CONN_TYPE_TO_STRING(conn->type), conn->state,
conn->outbuf_flushlen, conn->marked_for_close_file, conn->marked_for_close); conn->outbuf_flushlen, conn->marked_for_close_file, conn->marked_for_close);
if(connection_speaks_cells(conn)) { if(connection_speaks_cells(conn)) {
if(conn->state == OR_CONN_STATE_OPEN) { if(conn->state == OR_CONN_STATE_OPEN) {
@ -332,7 +330,7 @@ static void conn_close_if_marked(int i) {
} }
if(connection_wants_to_flush(conn)) { if(connection_wants_to_flush(conn)) {
log_fn(LOG_WARN,"Conn (addr %s, fd %d, type %s, state %d) still wants to flush. Losing %d bytes! (Marked at %s:%d)", log_fn(LOG_WARN,"Conn (addr %s, fd %d, type %s, state %d) still wants to flush. Losing %d bytes! (Marked at %s:%d)",
inet_ntoa(in), conn->s, CONN_TYPE_TO_STRING(conn->type), conn->state, conn->address, conn->s, CONN_TYPE_TO_STRING(conn->type), conn->state,
(int)buf_datalen(conn->outbuf), conn->marked_for_close_file, (int)buf_datalen(conn->outbuf), conn->marked_for_close_file,
conn->marked_for_close); conn->marked_for_close);
} }

View File

@ -47,7 +47,7 @@ int onion_pending_add(circuit_t *circ) {
if(ol_length >= options.MaxOnionsPending) { if(ol_length >= options.MaxOnionsPending) {
log_fn(LOG_WARN,"Already have %d onions queued. Closing.", ol_length); log_fn(LOG_WARN,"Already have %d onions queued. Closing.", ol_length);
free(tmp); tor_free(tmp);
return -1; return -1;
} }
@ -109,7 +109,7 @@ void onion_pending_remove(circuit_t *circ) {
/* now victim points to the element that needs to be removed */ /* now victim points to the element that needs to be removed */
free(victim); tor_free(victim);
} }
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/

View File

@ -767,7 +767,7 @@ int router_dump_router_to_string(char *s, int maxlen, routerinfo_t *router,
s); s);
return -1; return -1;
} }
free(s_dup); tor_free(s_dup);
routerinfo_free(ri_tmp); routerinfo_free(ri_tmp);
#endif #endif

View File

@ -540,7 +540,7 @@ void routerinfo_free(routerinfo_t *router)
if (router->identity_pkey) if (router->identity_pkey)
crypto_free_pk_env(router->identity_pkey); crypto_free_pk_env(router->identity_pkey);
exit_policy_free(router->exit_policy); exit_policy_free(router->exit_policy);
free(router); tor_free(router);
} }
/** Allocate a fresh copy of <b>router</b> */ /** Allocate a fresh copy of <b>router</b> */
@ -717,12 +717,12 @@ int router_load_routerlist_from_file(char *routerfile, int trusted)
if(router_load_routerlist_from_string(string, trusted) < 0) { if(router_load_routerlist_from_string(string, trusted) < 0) {
log_fn(LOG_WARN,"The routerfile itself was corrupt."); log_fn(LOG_WARN,"The routerfile itself was corrupt.");
free(string); tor_free(string);
return -1; return -1;
} }
/* dump_onion_keys(LOG_NOTICE); */ /* dump_onion_keys(LOG_NOTICE); */
free(string); tor_free(string);
return 0; return 0;
} }

View File

@ -872,7 +872,7 @@ router_parse_exit_policy_from_string(const char *s)
err: err:
r = NULL; r = NULL;
done: done:
free(tmp); tor_free(tmp);
token_free(tok); token_free(tok);
return r; return r;
} }
@ -1009,7 +1009,7 @@ policy_read_failed:
tor_assert(newe->string); tor_assert(newe->string);
log_fn(LOG_WARN,"Couldn't parse line '%s'. Dropping", newe->string); log_fn(LOG_WARN,"Couldn't parse line '%s'. Dropping", newe->string);
tor_free(newe->string); tor_free(newe->string);
free(newe); tor_free(newe);
return NULL; return NULL;
} }