Commit 0792cc10 authored by Nick Mathewson's avatar Nick Mathewson 🎨
Browse files

Convert connection_free to a nulling macro.

parent a48ba072
...@@ -1087,7 +1087,7 @@ circuit_free_all(void) ...@@ -1087,7 +1087,7 @@ circuit_free_all(void)
while (or_circ->resolving_streams) { while (or_circ->resolving_streams) {
edge_connection_t *next_conn; edge_connection_t *next_conn;
next_conn = or_circ->resolving_streams->next_stream; next_conn = or_circ->resolving_streams->next_stream;
connection_free(TO_CONN(or_circ->resolving_streams)); connection_free_(TO_CONN(or_circ->resolving_streams));
or_circ->resolving_streams = next_conn; or_circ->resolving_streams = next_conn;
} }
} }
......
/* Copyright (c) 2001 Matej Pfajfar. /* Copyright (c) 2001 Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine. * Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
* Copyright (c) 2007-2017, The Tor Project, Inc. */ * Copyright (c) 2007-2017, The Tor Project, Inc. */
...@@ -675,7 +675,7 @@ connection_free_minimal(connection_t *conn) ...@@ -675,7 +675,7 @@ connection_free_minimal(connection_t *conn)
/** Make sure <b>conn</b> isn't in any of the global conn lists; then free it. /** Make sure <b>conn</b> isn't in any of the global conn lists; then free it.
*/ */
MOCK_IMPL(void, MOCK_IMPL(void,
connection_free,(connection_t *conn)) connection_free_,(connection_t *conn))
{ {
if (!conn) if (!conn)
return; return;
......
...@@ -29,7 +29,8 @@ connection_t *connection_new(int type, int socket_family); ...@@ -29,7 +29,8 @@ connection_t *connection_new(int type, int socket_family);
int connection_init_accepted_conn(connection_t *conn, int connection_init_accepted_conn(connection_t *conn,
const listener_connection_t *listener); const listener_connection_t *listener);
void connection_link_connections(connection_t *conn_a, connection_t *conn_b); void connection_link_connections(connection_t *conn_a, connection_t *conn_b);
MOCK_DECL(void,connection_free,(connection_t *conn)); MOCK_DECL(void,connection_free_,(connection_t *conn));
#define connection_free(conn) FREE_AND_NULL(connection, (conn))
void connection_free_all(void); void connection_free_all(void);
void connection_about_to_close_connection(connection_t *conn); void connection_about_to_close_connection(connection_t *conn);
void connection_close_immediate(connection_t *conn); void connection_close_immediate(connection_t *conn);
......
...@@ -3327,7 +3327,7 @@ handle_hs_exit_conn(circuit_t *circ, edge_connection_t *conn) ...@@ -3327,7 +3327,7 @@ handle_hs_exit_conn(circuit_t *circ, edge_connection_t *conn)
relay_send_end_cell_from_edge(conn->stream_id, circ, relay_send_end_cell_from_edge(conn->stream_id, circ,
END_STREAM_REASON_DONE, END_STREAM_REASON_DONE,
origin_circ->cpath->prev); origin_circ->cpath->prev);
connection_free(TO_CONN(conn)); connection_free_(TO_CONN(conn));
/* Drop the circuit here since it might be someone deliberately /* Drop the circuit here since it might be someone deliberately
* scanning the hidden service ports. Note that this mitigates port * scanning the hidden service ports. Note that this mitigates port
...@@ -3524,7 +3524,7 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ) ...@@ -3524,7 +3524,7 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ)
if (we_are_hibernating()) { if (we_are_hibernating()) {
relay_send_end_cell_from_edge(rh.stream_id, circ, relay_send_end_cell_from_edge(rh.stream_id, circ,
END_STREAM_REASON_HIBERNATING, NULL); END_STREAM_REASON_HIBERNATING, NULL);
connection_free(TO_CONN(n_stream)); connection_free_(TO_CONN(n_stream));
return 0; return 0;
} }
...@@ -3602,7 +3602,7 @@ connection_exit_begin_resolve(cell_t *cell, or_circuit_t *circ) ...@@ -3602,7 +3602,7 @@ connection_exit_begin_resolve(cell_t *cell, or_circuit_t *circ)
return 0; return 0;
case 1: /* The result was cached; a resolved cell was sent. */ case 1: /* The result was cached; a resolved cell was sent. */
if (!dummy_conn->base_.marked_for_close) if (!dummy_conn->base_.marked_for_close)
connection_free(TO_CONN(dummy_conn)); connection_free_(TO_CONN(dummy_conn));
return 0; return 0;
case 0: /* resolve added to pending list */ case 0: /* resolve added to pending list */
assert_circuit_ok(TO_CIRCUIT(circ)); assert_circuit_ok(TO_CIRCUIT(circ));
...@@ -3775,8 +3775,8 @@ connection_exit_connect_dir(edge_connection_t *exitconn) ...@@ -3775,8 +3775,8 @@ connection_exit_connect_dir(edge_connection_t *exitconn)
if (connection_add(TO_CONN(exitconn))<0) { if (connection_add(TO_CONN(exitconn))<0) {
connection_edge_end(exitconn, END_STREAM_REASON_RESOURCELIMIT); connection_edge_end(exitconn, END_STREAM_REASON_RESOURCELIMIT);
connection_free(TO_CONN(exitconn)); connection_free_(TO_CONN(exitconn));
connection_free(TO_CONN(dirconn)); connection_free_(TO_CONN(dirconn));
return 0; return 0;
} }
...@@ -3788,7 +3788,7 @@ connection_exit_connect_dir(edge_connection_t *exitconn) ...@@ -3788,7 +3788,7 @@ connection_exit_connect_dir(edge_connection_t *exitconn)
connection_edge_end(exitconn, END_STREAM_REASON_RESOURCELIMIT); connection_edge_end(exitconn, END_STREAM_REASON_RESOURCELIMIT);
connection_close_immediate(TO_CONN(exitconn)); connection_close_immediate(TO_CONN(exitconn));
connection_mark_for_close(TO_CONN(exitconn)); connection_mark_for_close(TO_CONN(exitconn));
connection_free(TO_CONN(dirconn)); connection_free_(TO_CONN(dirconn));
return 0; return 0;
} }
......
...@@ -1247,7 +1247,7 @@ connection_or_connect, (const tor_addr_t *_addr, uint16_t port, ...@@ -1247,7 +1247,7 @@ connection_or_connect, (const tor_addr_t *_addr, uint16_t port,
fmt_addrport(&TO_CONN(conn)->addr, TO_CONN(conn)->port)); fmt_addrport(&TO_CONN(conn)->addr, TO_CONN(conn)->port));
} }
connection_free(TO_CONN(conn)); connection_free_(TO_CONN(conn));
return NULL; return NULL;
} }
...@@ -1260,7 +1260,7 @@ connection_or_connect, (const tor_addr_t *_addr, uint16_t port, ...@@ -1260,7 +1260,7 @@ connection_or_connect, (const tor_addr_t *_addr, uint16_t port,
connection_or_connect_failed(conn, connection_or_connect_failed(conn,
errno_to_orconn_end_reason(socket_error), errno_to_orconn_end_reason(socket_error),
tor_socket_strerror(socket_error)); tor_socket_strerror(socket_error));
connection_free(TO_CONN(conn)); connection_free_(TO_CONN(conn));
return NULL; return NULL;
case 0: case 0:
connection_watch_events(TO_CONN(conn), READ_EVENT | WRITE_EVENT); connection_watch_events(TO_CONN(conn), READ_EVENT | WRITE_EVENT);
......
...@@ -457,7 +457,7 @@ purge_expired_resolves(time_t now) ...@@ -457,7 +457,7 @@ purge_expired_resolves(time_t now)
if (!pendconn->base_.marked_for_close) { if (!pendconn->base_.marked_for_close) {
connection_edge_end(pendconn, END_STREAM_REASON_TIMEOUT); connection_edge_end(pendconn, END_STREAM_REASON_TIMEOUT);
circuit_detach_stream(circuit_get_by_edge_conn(pendconn), pendconn); circuit_detach_stream(circuit_get_by_edge_conn(pendconn), pendconn);
connection_free(TO_CONN(pendconn)); connection_free_(TO_CONN(pendconn));
} }
tor_free(pend); tor_free(pend);
} }
...@@ -670,7 +670,7 @@ dns_resolve(edge_connection_t *exitconn) ...@@ -670,7 +670,7 @@ dns_resolve(edge_connection_t *exitconn)
/* If we made the connection pending, then we freed it already in /* If we made the connection pending, then we freed it already in
* dns_cancel_pending_resolve(). If we marked it for close, it'll * dns_cancel_pending_resolve(). If we marked it for close, it'll
* get freed from the main loop. Otherwise, can free it now. */ * get freed from the main loop. Otherwise, can free it now. */
connection_free(TO_CONN(exitconn)); connection_free_(TO_CONN(exitconn));
} }
break; break;
default: default:
...@@ -1101,7 +1101,7 @@ dns_cancel_pending_resolve,(const char *address)) ...@@ -1101,7 +1101,7 @@ dns_cancel_pending_resolve,(const char *address))
if (circ) if (circ)
circuit_detach_stream(circ, pendconn); circuit_detach_stream(circ, pendconn);
if (!pendconn->base_.marked_for_close) if (!pendconn->base_.marked_for_close)
connection_free(TO_CONN(pendconn)); connection_free_(TO_CONN(pendconn));
resolve->pending_connections = pend->next; resolve->pending_connections = pend->next;
tor_free(pend); tor_free(pend);
} }
...@@ -1230,7 +1230,7 @@ inform_pending_connections(cached_resolve_t *resolve) ...@@ -1230,7 +1230,7 @@ inform_pending_connections(cached_resolve_t *resolve)
/* This detach must happen after we send the resolved cell. */ /* This detach must happen after we send the resolved cell. */
circuit_detach_stream(circuit_get_by_edge_conn(pendconn), pendconn); circuit_detach_stream(circuit_get_by_edge_conn(pendconn), pendconn);
} }
connection_free(TO_CONN(pendconn)); connection_free_(TO_CONN(pendconn));
} else { } else {
circuit_t *circ; circuit_t *circ;
if (pendconn->base_.purpose == EXIT_PURPOSE_CONNECT) { if (pendconn->base_.purpose == EXIT_PURPOSE_CONNECT) {
...@@ -1259,7 +1259,7 @@ inform_pending_connections(cached_resolve_t *resolve) ...@@ -1259,7 +1259,7 @@ inform_pending_connections(cached_resolve_t *resolve)
circ = circuit_get_by_edge_conn(pendconn); circ = circuit_get_by_edge_conn(pendconn);
tor_assert(circ); tor_assert(circ);
circuit_detach_stream(circ, pendconn); circuit_detach_stream(circ, pendconn);
connection_free(TO_CONN(pendconn)); connection_free_(TO_CONN(pendconn));
} }
} }
resolve->pending_connections = pend->next; resolve->pending_connections = pend->next;
......
...@@ -172,7 +172,7 @@ evdns_server_callback(struct evdns_server_request *req, void *data_) ...@@ -172,7 +172,7 @@ evdns_server_callback(struct evdns_server_request *req, void *data_)
if (connection_add(ENTRY_TO_CONN(entry_conn)) < 0) { if (connection_add(ENTRY_TO_CONN(entry_conn)) < 0) {
log_warn(LD_APP, "Couldn't register dummy connection for DNS request"); log_warn(LD_APP, "Couldn't register dummy connection for DNS request");
evdns_server_request_respond(req, DNS_ERR_SERVERFAILED); evdns_server_request_respond(req, DNS_ERR_SERVERFAILED);
connection_free(ENTRY_TO_CONN(entry_conn)); connection_free_(ENTRY_TO_CONN(entry_conn));
return; return;
} }
...@@ -249,7 +249,7 @@ dnsserv_launch_request(const char *name, int reverse, ...@@ -249,7 +249,7 @@ dnsserv_launch_request(const char *name, int reverse,
if (connection_add(TO_CONN(conn))<0) { if (connection_add(TO_CONN(conn))<0) {
log_warn(LD_APP, "Couldn't register dummy connection for RESOLVE request"); log_warn(LD_APP, "Couldn't register dummy connection for RESOLVE request");
connection_free(TO_CONN(conn)); connection_free_(TO_CONN(conn));
return -1; return -1;
} }
......
...@@ -124,7 +124,7 @@ static int n_connection_free = 0; ...@@ -124,7 +124,7 @@ static int n_connection_free = 0;
static connection_t *last_freed_conn = NULL; static connection_t *last_freed_conn = NULL;
static void static void
NS(connection_free)(connection_t *conn) NS(connection_free_)(connection_t *conn)
{ {
n_connection_free++; n_connection_free++;
...@@ -267,7 +267,7 @@ NS(test_main)(void *arg) ...@@ -267,7 +267,7 @@ NS(test_main)(void *arg)
*/ */
NS_MOCK(dns_cancel_pending_resolve); NS_MOCK(dns_cancel_pending_resolve);
NS_MOCK(connection_free); NS_MOCK(connection_free_);
exitconn->on_circuit = &(on_circuit->base_); exitconn->on_circuit = &(on_circuit->base_);
exitconn->base_.purpose = EXIT_PURPOSE_RESOLVE; exitconn->base_.purpose = EXIT_PURPOSE_RESOLVE;
...@@ -294,7 +294,7 @@ NS(test_main)(void *arg) ...@@ -294,7 +294,7 @@ NS(test_main)(void *arg)
NS_UNMOCK(send_resolved_cell); NS_UNMOCK(send_resolved_cell);
NS_UNMOCK(send_resolved_hostname_cell); NS_UNMOCK(send_resolved_hostname_cell);
NS_UNMOCK(dns_cancel_pending_resolve); NS_UNMOCK(dns_cancel_pending_resolve);
NS_UNMOCK(connection_free); NS_UNMOCK(connection_free_);
tor_free(on_circuit); tor_free(on_circuit);
tor_free(exitconn); tor_free(exitconn);
tor_free(nextconn); tor_free(nextconn);
......
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