From 688cea7248584b0202fc269a9f009bfa97e598bc Mon Sep 17 00:00:00 2001 From: Andrea Shepard Date: Tue, 6 Nov 2012 17:52:14 -0800 Subject: Check for closing channel in channel_send_destroy() --- src/or/channel.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'src/or/channel.c') 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; } -- cgit v1.2.3-54-g00ecf