diff options
author | Andrea Shepard <andrea@torproject.org> | 2012-11-06 17:52:14 -0800 |
---|---|---|
committer | Andrea Shepard <andrea@torproject.org> | 2012-11-06 17:52:14 -0800 |
commit | 688cea7248584b0202fc269a9f009bfa97e598bc (patch) | |
tree | 5ca95b2fe6aae4386b43f9e8b8094228c0dc8c73 /src | |
parent | 39a0a2c3ae8c93ceed42f6d2d1143002c231fc16 (diff) | |
download | tor-688cea7248584b0202fc269a9f009bfa97e598bc.tar.gz tor-688cea7248584b0202fc269a9f009bfa97e598bc.zip |
Check for closing channel in channel_send_destroy()
Diffstat (limited to 'src')
-rw-r--r-- | src/or/channel.c | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/or/channel.c b/src/or/channel.c index cbf7f99be1..16dd9f903a 100644 --- a/src/or/channel.c +++ b/src/or/channel.c @@ -2585,17 +2585,29 @@ channel_send_destroy(circid_t circ_id, channel_t *chan, int reason) tor_assert(chan); - memset(&cell, 0, sizeof(cell_t)); - cell.circ_id = circ_id; - cell.command = CELL_DESTROY; - cell.payload[0] = (uint8_t) reason; - log_debug(LD_OR, - "Sending destroy (circID %d) on channel %p " - "(global ID " U64_FORMAT ")", - circ_id, chan, - U64_PRINTF_ARG(chan->global_identifier)); + /* Check to make sure we can send on this channel first */ + if (!(chan->state == CHANNEL_STATE_CLOSING || + chan->state == CHANNEL_STATE_CLOSED || + chan->state == CHANNEL_STATE_ERROR)) { + memset(&cell, 0, sizeof(cell_t)); + cell.circ_id = circ_id; + cell.command = CELL_DESTROY; + cell.payload[0] = (uint8_t) reason; + log_debug(LD_OR, + "Sending destroy (circID %d) on channel %p " + "(global ID " U64_FORMAT ")", + circ_id, chan, + U64_PRINTF_ARG(chan->global_identifier)); - channel_write_cell(chan, &cell); + channel_write_cell(chan, &cell); + } else { + log_warn(LD_BUG, + "Someone called channel_send_destroy() for circID %d " + "on a channel " U64_FORMAT " at %p in state %s (%d)", + circ_id, U64_PRINTF_ARG(chan->global_identifier), + chan, channel_state_to_string(chan->state), + chan->state); + } return 0; } |