summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Shepard <andrea@torproject.org>2012-10-15 06:32:44 -0700
committerAndrea Shepard <andrea@torproject.org>2012-10-15 06:32:44 -0700
commit9ef286ec8f10f88a5b30f48efd502b9c87933762 (patch)
tree84b1caa8b78e0d52fead1ff62da06755b75a2928
parent45d7fb44c44867f2c44752935663547a3e8d85dd (diff)
downloadtor-9ef286ec8f10f88a5b30f48efd502b9c87933762.tar.gz
tor-9ef286ec8f10f88a5b30f48efd502b9c87933762.zip
Correctly clear cmux policies and free cmux in channel_free() and channel_force_free()
-rw-r--r--src/or/channel.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/or/channel.c b/src/or/channel.c
index 6527288c4a..56e15b48b8 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -808,11 +808,20 @@ channel_free(channel_t *chan)
/* It must be deregistered */
tor_assert(!(chan->registered));
+ /*
+ * Get rid of cmux policy before we do anything, so cmux policies don't
+ * see channels in weird half-freed states.
+ */
+ if (chan->cmux) {
+ circuitmux_set_policy(chan->cmux, NULL);
+ }
+
/* Call a free method if there is one */
if (chan->free) chan->free(chan);
channel_clear_remote_end(chan);
+ /* Get rid of cmux */
if (chan->cmux) {
circuitmux_detach_all_circuits(chan->cmux);
circuitmux_free(chan->cmux);
@@ -863,11 +872,25 @@ channel_force_free(channel_t *chan)
{
tor_assert(chan);
+ /*
+ * Get rid of cmux policy before we do anything, so cmux policies don't
+ * see channels in weird half-freed states.
+ */
+ if (chan->cmux) {
+ circuitmux_set_policy(chan->cmux, NULL);
+ }
+
/* Call a free method if there is one */
if (chan->free) chan->free(chan);
channel_clear_remote_end(chan);
+ /* Get rid of cmux */
+ if (chan->cmux) {
+ circuitmux_free(chan->cmux);
+ chan->cmux = NULL;
+ }
+
/* We might still have a cell queue; kill it */
if (chan->incoming_queue) {
SMARTLIST_FOREACH_BEGIN(chan->incoming_queue,